Files
Khem Raj e8b8f3ddd9 bpftrace: link test data source binary without host runtime
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.

Because the object is now linked -nostdlib it must not reference the
libc stack-protector runtime. Host gcc toolchains that default to
-fstack-protector-strong (e.g. Debian/Ubuntu and the Yocto
autobuilder workers) otherwise leave an undefined reference and the
link fails:

  ld: data_source.o: in function `main':
  data_source.c:212: undefined reference to `__stack_chk_fail'
  collect2: error: ld returned 1 exit status

Compile the object and link the binary with -fno-stack-protector; the
canary is irrelevant to a DWARF/BTF carrier that is never run.

Signed-off-by: Khem Raj <khem.raj@oss.qualcomm.com>
2026-07-12 17:39:43 -07:00

83 lines
2.7 KiB
BlitzBasic

SUMMARY = "bpftrace"
HOMEPAGE = "https://github.com/iovisor/bpftrace"
LICENSE = "Apache-2.0"
LIC_FILES_CHKSUM = "file://LICENSE;md5=3b83ef96387f14655fc854ddc3c6bd57"
DEPENDS += "bison-native \
flex-native \
gzip-native \
elfutils \
bpftool-native \
bcc \
libcereal \
libbpf \
xxd-native \
"
DEPENDS += "${@bb.utils.contains('PTEST_ENABLED', '1', 'pahole-native llvm-native', '', d)}"
SRC_URI = "git://github.com/iovisor/bpftrace;branch=release/0.25.x;protocol=https;tag=v${PV} \
file://run-ptest \
file://0002-CMakeLists.txt-allow-to-set-BISON_FLAGS-like-l.patch \
file://0001-cmake-BuildBPF.cmake-introduce-DEBUG_PREFIX_MAP.patch \
file://0003-cmake-BuildBPF.cmake-link-data-source-binary-without.patch \
"
SRCREV = "e491811e5d648288c01f42ce087967b271f504a0"
inherit bash-completion cmake ptest pkgconfig
export DEBUG_PREFIX_MAP
PACKAGECONFIG ?= " \
${@bb.utils.contains('PTEST_ENABLED', '1', 'tests', '', d)} \
${@bb.utils.contains("DISTRO_FEATURES", "systemd", "systemd", "", d)} \
"
PACKAGECONFIG[tests] = "-DBUILD_TESTING=ON,-DBUILD_TESTING=OFF,gtest"
PACKAGECONFIG[systemd] = "-DENABLE_SYSTEMD=ON,-DENABLE_SYSTEMD=OFF,systemd"
do_install_ptest() {
if [ -e ${B}/tests/bpftrace_test ]; then
install -Dm 755 ${B}/tests/bpftrace_test ${D}${PTEST_PATH}/tests/bpftrace_test
cp -rf ${B}/tests/runtime ${D}${PTEST_PATH}/tests
cp -rf ${B}/tests/test* ${D}${PTEST_PATH}/tests
fi
for f in testlibs/cmake_install.cmake \
testprogs/cmake_install.cmake \
testlibs/CTestTestfile.cmake \
testprogs/CTestTestfile.cmake
do
sed -i -e 's|${STAGING_BINDIR_TOOLCHAIN}/||' ${D}${libdir}/bpftrace/ptest/tests/$f
sed -i -e 's|${S}/||' ${D}${libdir}/bpftrace/ptest/tests/$f
sed -i -e 's|${B}/||' ${D}${libdir}/bpftrace/ptest/tests/$f
done
}
do_install_ptest:powerpc64() {
}
do_install_ptest:powerpc64le() {
}
EXTRA_OECMAKE = " \
-DCMAKE_ENABLE_EXPORTS=1 \
-DCMAKE_BUILD_TYPE=Release \
-DUSE_SYSTEM_BPF_BCC=ON \
-DUSE_SYSTEM_LIBBPF=ON \
-DENABLE_MAN=OFF \
-DBISON_FLAGS='--file-prefix-map=${WORKDIR}=' \
"
PACKAGES:remove:powerpc64 = "${PN}-ptest"
PACKAGES:remove:powerpc64le = "${PN}-ptest"
RDEPENDS:${PN}-ptest += "bash bpftool python3"
COMPATIBLE_HOST = "(x86_64.*|aarch64.*|powerpc64.*|riscv64.*)-linux"
INHIBIT_PACKAGE_STRIP_FILES += "\
${PKGD}${PTEST_PATH}/tests/testprogs/uprobe_test \
"
WARN_QA:append = "${@bb.utils.contains('PTEST_ENABLED', '1', ' buildpaths', '', d)}"
ERROR_QA:remove = "${@bb.utils.contains('PTEST_ENABLED', '1', 'buildpaths', '', d)}"