Skip to content

Commit 7470901

Browse files
committed
bpftrace: fix buildpaths QA issue for build host HOME directory
The build host HOME directory check recently added to OE-Core's buildpaths QA test flags the ptest gtest binary: WARNING: bpftrace-0.25.1-r0 do_package_qa: QA Issue: File /usr/lib/bpftrace/ptest/tests/bpftrace_test in package bpftrace-ptest contains a reference to the build host HOME directory. [buildpaths] WARNING: bpftrace-0.25.1-r0 do_package_qa: QA Issue: File /usr/lib/bpftrace/ptest/tests/.debug/bpftrace_test in package bpftrace-dbg contains a reference to the build host HOME directory. [buildpaths] cmake/BuildBPF.cmake links the intermediate DWARF carrier binary data_source_exe with the plain build host gcc, which bakes the host dynamic loader's absolute path into the PT_INTERP segment. With a distro gcc that is an innocuous /lib64/ld-linux-x86-64.so.2, but when the host toolchain is a buildtools-extended/SDK gcc installed under the build user's home directory (as on the autobuilder workers), it is a $HOME-prefixed path like /srv/pokybuild/.../buildtools/sysroots/x86_64-pokysdk-linux/lib/ld-linux-x86-64.so.2 The executable is then embedded byte-for-byte into bpftrace_test via embed()/xxd (tests/data/CMakeLists.txt), so the path ends up in the test binary's .rodata, triggering the bpftrace-ptest warning. And because cmake/Embed.tmpl declares the embedded blob as a constexpr array, gcc additionally copies its contents into .debug_info as DW_AT_const_value, which is how the same string survives objcopy --only-keep-debug into the split debug file, triggering the bpftrace-dbg warning. This is the same embedding mechanism that previously leaked TMPDIR paths, fixed for the compile step by the DEBUG_PREFIX_MAP patch; the link step was still leaking. The tests only write this binary to a temp file and use it as a uprobe target (tests/dwarf_common.h), parsing its DWARF and symbols; it is never executed. So link it with -nostdlib -no-pie -Wl,--entry=0: no interpreter, no host crt objects, no dynamic segment, and thus nothing host-specific in the embedded blob. Function symbols, DWARF type information and the pahole -J BTF encoding step are unaffected, and the field_analyser_dwarf ptests still pass. Signed-off-by: Khem Raj <khem.raj@oss.qualcomm.com>
1 parent db181df commit 7470901

2 files changed

Lines changed: 58 additions & 0 deletions

File tree

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
From: Khem Raj <khem.raj@oss.qualcomm.com>
2+
Date: Thu, 2 Jul 2026 15:30:00 -0700
3+
Subject: [PATCH] cmake/BuildBPF.cmake: link data source binary without host
4+
runtime
5+
6+
The `bpf()` helper links the intermediate DWARF carrier binary
7+
(data_source_exe) with the plain host gcc:
8+
9+
${GCC} -g -o data_source_exe data_source.o
10+
11+
and the resulting executable is then embedded byte-for-byte into
12+
bpftrace_test via embed()/xxd (tests/data/CMakeLists.txt). Linking it as
13+
a regular dynamic executable bakes host-toolchain artifacts into it:
14+
15+
* PT_INTERP: the absolute path of the host toolchain's dynamic
16+
loader. With a vendored/SDK toolchain (e.g. Yocto
17+
buildtools-extended installed under the build user's home) this is
18+
an absolute build-host path such as
19+
/srv/pokybuild/.../buildtools/sysroots/x86_64-pokysdk-linux/lib/ld-linux-x86-64.so.2
20+
* crt startup objects (crt1.o, crti.o, crtbegin.o) including whatever
21+
debug info the host libc was built with.
22+
23+
Since the embedded blob carries these strings into the packaged test
24+
binary, the build is not reproducible across hosts and leaks build host
25+
paths, flagged by OE's buildpaths QA check:
26+
27+
WARNING: bpftrace-0.25.1-r0 do_package_qa: QA Issue: File
28+
/usr/lib/bpftrace/ptest/tests/bpftrace_test in package bpftrace-ptest
29+
contains a reference to the build host HOME directory. [buildpaths]
30+
31+
The binary only serves as a DWARF/BTF container: the tests write it to
32+
a temp file and use it as a uprobe target (tests/dwarf_common.h), which
33+
parses debug info and symbols but never executes it. So link it with
34+
-nostdlib -no-pie: no interpreter, no dynamic segment, no host crt
35+
code. -Wl,--entry=0 silences the "cannot find entry symbol _start"
36+
warning. All function symbols, DWARF type information and the
37+
pahole -J BTF encoding step are unaffected.
38+
39+
Upstream-Status: Pending
40+
Signed-off-by: Khem Raj <khem.raj@oss.qualcomm.com>
41+
---
42+
cmake/BuildBPF.cmake | 2 +-
43+
1 file changed, 1 insertion(+), 1 deletion(-)
44+
45+
diff --git a/cmake/BuildBPF.cmake b/cmake/BuildBPF.cmake
46+
index cb8cd68..8aa059f 100644
47+
--- a/cmake/BuildBPF.cmake
48+
+++ b/cmake/BuildBPF.cmake
49+
@@ -107,7 +107,7 @@ function(bpf NAME)
50+
add_custom_command(
51+
OUTPUT ${ARG_BINARY}
52+
DEPENDS ${ARG_SOURCE} ${NAME}_gen_object
53+
- COMMAND ${GCC} -g -o ${CMAKE_CURRENT_BINARY_DIR}/${ARG_BINARY} ${CMAKE_CURRENT_BINARY_DIR}/${ARG_OBJECT}
54+
+ COMMAND ${GCC} -g -nostdlib -no-pie -Wl,--entry=0 -o ${CMAKE_CURRENT_BINARY_DIR}/${ARG_BINARY} ${CMAKE_CURRENT_BINARY_DIR}/${ARG_OBJECT}
55+
COMMAND cmake -E env LLVM_OBJCOPY=${LLVM_OBJCOPY} ${PAHOLE} -J ${CMAKE_CURRENT_BINARY_DIR}/${ARG_BINARY}
56+
VERBATIM
57+
)

meta-oe/dynamic-layers/meta-python/recipes-devtools/bpftrace/bpftrace_0.25.1.bb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ SRC_URI = "git://github.com/iovisor/bpftrace;branch=release/0.25.x;protocol=http
1919
file://run-ptest \
2020
file://0002-CMakeLists.txt-allow-to-set-BISON_FLAGS-like-l.patch \
2121
file://0001-cmake-BuildBPF.cmake-introduce-DEBUG_PREFIX_MAP.patch \
22+
file://0003-cmake-BuildBPF.cmake-link-data-source-binary-without.patch \
2223
"
2324
SRCREV = "e491811e5d648288c01f42ce087967b271f504a0"
2425

0 commit comments

Comments
 (0)