diff options
author | Khem Raj <raj.khem@gmail.com> | 2025-07-15 12:39:58 -0700 |
---|---|---|
committer | Khem Raj <raj.khem@gmail.com> | 2025-07-16 08:47:50 -0700 |
commit | 1db713b038cfeeb37b8c571950d7354c88eeac8c (patch) | |
tree | 2c76b33ac1466916a1ad3ecaa0c5117c8c03f1e7 | |
parent | 2b9e429a242d8899c77281b6c2387b63534b8d82 (diff) | |
download | meta-openembedded-1db713b038cfeeb37b8c571950d7354c88eeac8c.tar.gz |
bpftrace,bcc: Migrate recipe from meta-clang to meta-oe
These recipes depend on clang, and clang being on core
it is better place for these tools to be in a common
layer for now that is meta-oe
Signed-off-by: Khem Raj <raj.khem@gmail.com>
10 files changed, 559 insertions, 0 deletions
diff --git a/meta-oe/dynamic-layers/meta-python/recipes-devtools/bcc/bcc/0001-CMakeLists.txt-override-the-PY_CMD_ESCAPED.patch b/meta-oe/dynamic-layers/meta-python/recipes-devtools/bcc/bcc/0001-CMakeLists.txt-override-the-PY_CMD_ESCAPED.patch new file mode 100644 index 0000000000..1f9c41dfab --- /dev/null +++ b/meta-oe/dynamic-layers/meta-python/recipes-devtools/bcc/bcc/0001-CMakeLists.txt-override-the-PY_CMD_ESCAPED.patch | |||
@@ -0,0 +1,41 @@ | |||
1 | From 4f64ed40e1ffea7ea278627f30a01018e57dcbcf Mon Sep 17 00:00:00 2001 | ||
2 | From: Mingli Yu <mingli.yu@windriver.com> | ||
3 | Date: Wed, 9 Sep 2020 05:48:19 +0000 | ||
4 | Subject: [PATCH] CMakeLists.txt: override the PY_CMD_ESCAPED | ||
5 | |||
6 | Override the PY_CMD_ESCAPED as the PY_CMD_ESCAPED is constructed by | ||
7 | the full path of the python3. In some cases, the path is so long and | ||
8 | result in the PY_CMD_ESCAPED exceeds 255 characters and comes below | ||
9 | do_configure error: | ||
10 | | CMake Error at src/python/CMakeLists.txt:18 (configure_file): | ||
11 | | configure_file Problem configuring file | ||
12 | | | ||
13 | | CMake Error: Could not open file for write in copy operation /buildarea1/test/wr_build/wr1020_20200909_bcc/bcc_long_Kernel/auto-standalone_next/200827/lxbuilds/Intel-Snow-Ridge-NS_platform_up/intel-x86-64-standard-glibc-std/wrlinux/build/tmp-glibc/work/corei7-64-wrs-linux/bcc/0.15.0-r0/build/src/python/bcc--buildarea1-test-wr_build-wr1020_20200909_bcc-bcc_long_Kernel-auto-standalone_next-200827-lxbuilds-Intel-Snow-Ridge-NS_platform_up-intel-x86-64-standard-glibc-std-wrlinux-build-tmp-glibc-work-corei7-64-wrs-linux-bcc-0.15.0-r0-recipe-sysroot-native-usr-bin-python3-native-python3/bcc/version.py.tmp | ||
14 | |||
15 | Upstream-Status: Pending | ||
16 | |||
17 | Signed-off-by: Mingli Yu <mingli.yu@windriver.com> | ||
18 | --- | ||
19 | src/python/CMakeLists.txt | 4 ++-- | ||
20 | 1 file changed, 2 insertions(+), 2 deletions(-) | ||
21 | |||
22 | --- a/src/python/CMakeLists.txt | ||
23 | +++ b/src/python/CMakeLists.txt | ||
24 | @@ -16,7 +16,7 @@ file(GLOB_RECURSE PYTHON_INCLUDES RELATI | ||
25 | |||
26 | foreach(PY_CMD ${PYTHON_CMD}) | ||
27 | string(REPLACE "/" "-" PY_CMD_ESCAPED ${PY_CMD}) | ||
28 | - set(PY_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/bcc-${PY_CMD_ESCAPED}) | ||
29 | + set(PY_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/bcc-python3) | ||
30 | |||
31 | foreach(PY_SRC ${PYTHON_SOURCES}) | ||
32 | configure_file(${PY_SRC} ${PY_DIRECTORY}/${PY_SRC} COPYONLY) | ||
33 | @@ -35,7 +35,7 @@ foreach(PY_CMD ${PYTHON_CMD}) | ||
34 | DEPENDS ${PYTHON_SOURCES} ${PYTHON_INCLUDES} | ||
35 | COMMENT "Building sdist for ${PY_CMD}" | ||
36 | ) | ||
37 | - add_custom_target(bcc_py_${PY_CMD_ESCAPED} ALL DEPENDS ${PIP_INSTALLABLE}) | ||
38 | + add_custom_target(bcc_py_python3 ALL DEPENDS ${PIP_INSTALLABLE}) | ||
39 | |||
40 | if(NOT PYTHON_PREFIX) | ||
41 | set(PYTHON_PREFIX ${CMAKE_INSTALL_PREFIX}) | ||
diff --git a/meta-oe/dynamic-layers/meta-python/recipes-devtools/bcc/bcc/0001-Vendor-just-enough-extra-headers-to-allow-libbpf-to-.patch b/meta-oe/dynamic-layers/meta-python/recipes-devtools/bcc/bcc/0001-Vendor-just-enough-extra-headers-to-allow-libbpf-to-.patch new file mode 100644 index 0000000000..c3c787d26d --- /dev/null +++ b/meta-oe/dynamic-layers/meta-python/recipes-devtools/bcc/bcc/0001-Vendor-just-enough-extra-headers-to-allow-libbpf-to-.patch | |||
@@ -0,0 +1,124 @@ | |||
1 | From 6cffc195eca6b53a12865d325ff97e7b5ba8f22b Mon Sep 17 00:00:00 2001 | ||
2 | From: Daniel Thompson <daniel.thompson@linaro.org> | ||
3 | Date: Thu, 19 May 2022 09:14:20 +0000 | ||
4 | Subject: [PATCH] Vendor just enough extra headers to allow libbpf to be | ||
5 | de-vendored | ||
6 | |||
7 | Currently it is not possible to build the bcc recipe when we de-vendor | ||
8 | libbpf and adopt the packaged version. Ironically this is due to the | ||
9 | deliberate vendoring of some depreciated btf code that is being removed | ||
10 | upstream because bcc was the only user! In other words the vendored code | ||
11 | doesn't work the de-vendored libbpf because also ends up de-vendoring | ||
12 | one of the Linux uapi headers. | ||
13 | |||
14 | This is obviously an OE specific issue (due to the current combination | ||
15 | of linux headers, libbpf and bcc). It's a bit of a mess and the right | ||
16 | solution is probably to update the system UAPI headers but I am committing | ||
17 | this for now simply so I can easily show why we must de-vendor libbpf in | ||
18 | the first place! | ||
19 | |||
20 | Upstream-Status: Inappropriate [other] | ||
21 | |||
22 | Signed-off-by: Daniel Thompson <daniel.thompson@linaro.org> | ||
23 | --- | ||
24 | src/cc/bcc_btf.cc | 87 +++++++++++++++++++++++++++++++++++++++++++++++ | ||
25 | 1 file changed, 87 insertions(+) | ||
26 | |||
27 | diff --git a/src/cc/bcc_btf.cc b/src/cc/bcc_btf.cc | ||
28 | index 7f551ae8..cca3c6c3 100644 | ||
29 | --- a/src/cc/bcc_btf.cc | ||
30 | +++ b/src/cc/bcc_btf.cc | ||
31 | @@ -33,6 +33,93 @@ | ||
32 | |||
33 | namespace btf_ext_vendored { | ||
34 | |||
35 | +#ifdef HAVE_EXTERNAL_LIBBPF | ||
36 | +/* | ||
37 | + * When we de-vendor libbpf we end up picking up an older version of | ||
38 | + * [uapi/]linux/bpf.h which misses out some of the data structures needed | ||
39 | + * to compile this file. Annoyingly the code that doesn't compile it | ||
40 | + * a result of de-vendoring | ||
41 | + * | ||
42 | + * This section is a minimized re-vendoring to fix that. It is not robust | ||
43 | + * against version skew: When the system linux/bpf.h is updated then this | ||
44 | + * will break the build and the patch can be dropped. | ||
45 | + */ | ||
46 | + | ||
47 | +/* bpf_core_relo_kind encodes which aspect of captured field/type/enum value | ||
48 | + * has to be adjusted by relocations. It is emitted by llvm and passed to | ||
49 | + * libbpf and later to the kernel. | ||
50 | + */ | ||
51 | +enum bpf_core_relo_kind { | ||
52 | + BPF_CORE_FIELD_BYTE_OFFSET = 0, /* field byte offset */ | ||
53 | + BPF_CORE_FIELD_BYTE_SIZE = 1, /* field size in bytes */ | ||
54 | + BPF_CORE_FIELD_EXISTS = 2, /* field existence in target kernel */ | ||
55 | + BPF_CORE_FIELD_SIGNED = 3, /* field signedness (0 - unsigned, 1 - signed) */ | ||
56 | + BPF_CORE_FIELD_LSHIFT_U64 = 4, /* bitfield-specific left bitshift */ | ||
57 | + BPF_CORE_FIELD_RSHIFT_U64 = 5, /* bitfield-specific right bitshift */ | ||
58 | + BPF_CORE_TYPE_ID_LOCAL = 6, /* type ID in local BPF object */ | ||
59 | + BPF_CORE_TYPE_ID_TARGET = 7, /* type ID in target kernel */ | ||
60 | + BPF_CORE_TYPE_EXISTS = 8, /* type existence in target kernel */ | ||
61 | + BPF_CORE_TYPE_SIZE = 9, /* type size in bytes */ | ||
62 | + BPF_CORE_ENUMVAL_EXISTS = 10, /* enum value existence in target kernel */ | ||
63 | + BPF_CORE_ENUMVAL_VALUE = 11, /* enum value integer value */ | ||
64 | +}; | ||
65 | + | ||
66 | +/* | ||
67 | + * "struct bpf_core_relo" is used to pass relocation data form LLVM to libbpf | ||
68 | + * and from libbpf to the kernel. | ||
69 | + * | ||
70 | + * CO-RE relocation captures the following data: | ||
71 | + * - insn_off - instruction offset (in bytes) within a BPF program that needs | ||
72 | + * its insn->imm field to be relocated with actual field info; | ||
73 | + * - type_id - BTF type ID of the "root" (containing) entity of a relocatable | ||
74 | + * type or field; | ||
75 | + * - access_str_off - offset into corresponding .BTF string section. String | ||
76 | + * interpretation depends on specific relocation kind: | ||
77 | + * - for field-based relocations, string encodes an accessed field using | ||
78 | + * a sequence of field and array indices, separated by colon (:). It's | ||
79 | + * conceptually very close to LLVM's getelementptr ([0]) instruction's | ||
80 | + * arguments for identifying offset to a field. | ||
81 | + * - for type-based relocations, strings is expected to be just "0"; | ||
82 | + * - for enum value-based relocations, string contains an index of enum | ||
83 | + * value within its enum type; | ||
84 | + * - kind - one of enum bpf_core_relo_kind; | ||
85 | + * | ||
86 | + * Example: | ||
87 | + * struct sample { | ||
88 | + * int a; | ||
89 | + * struct { | ||
90 | + * int b[10]; | ||
91 | + * }; | ||
92 | + * }; | ||
93 | + * | ||
94 | + * struct sample *s = ...; | ||
95 | + * int *x = &s->a; // encoded as "0:0" (a is field #0) | ||
96 | + * int *y = &s->b[5]; // encoded as "0:1:0:5" (anon struct is field #1, | ||
97 | + * // b is field #0 inside anon struct, accessing elem #5) | ||
98 | + * int *z = &s[10]->b; // encoded as "10:1" (ptr is used as an array) | ||
99 | + * | ||
100 | + * type_id for all relocs in this example will capture BTF type id of | ||
101 | + * `struct sample`. | ||
102 | + * | ||
103 | + * Such relocation is emitted when using __builtin_preserve_access_index() | ||
104 | + * Clang built-in, passing expression that captures field address, e.g.: | ||
105 | + * | ||
106 | + * bpf_probe_read(&dst, sizeof(dst), | ||
107 | + * __builtin_preserve_access_index(&src->a.b.c)); | ||
108 | + * | ||
109 | + * In this case Clang will emit field relocation recording necessary data to | ||
110 | + * be able to find offset of embedded `a.b.c` field within `src` struct. | ||
111 | + * | ||
112 | + * [0] https://llvm.org/docs/LangRef.html#getelementptr-instruction | ||
113 | + */ | ||
114 | +struct bpf_core_relo { | ||
115 | + __u32 insn_off; | ||
116 | + __u32 type_id; | ||
117 | + __u32 access_str_off; | ||
118 | + enum bpf_core_relo_kind kind; | ||
119 | +}; | ||
120 | +#endif /* HAVE_EXTERNAL_LIBBPF */ | ||
121 | + | ||
122 | /* The minimum bpf_func_info checked by the loader */ | ||
123 | struct bpf_func_info_min { | ||
124 | uint32_t insn_off; | ||
diff --git a/meta-oe/dynamic-layers/meta-python/recipes-devtools/bcc/bcc/fix_for_memleak.patch b/meta-oe/dynamic-layers/meta-python/recipes-devtools/bcc/bcc/fix_for_memleak.patch new file mode 100644 index 0000000000..a3a1ec931d --- /dev/null +++ b/meta-oe/dynamic-layers/meta-python/recipes-devtools/bcc/bcc/fix_for_memleak.patch | |||
@@ -0,0 +1,16 @@ | |||
1 | Upstream-Status: Submitted [https://github.com/iovisor/bcc/pull/5355] | ||
2 | Signed-off-by: Harish Sadineni <Harish.Sadineni@windriver.com> | ||
3 | |||
4 | diff --git a/tests/python/test_tools_memleak.py b/tests/python/test_tools_memleak.py | ||
5 | --- a/tests/python/test_tools_memleak.py | ||
6 | +++ b/tests/python/test_tools_memleak.py | ||
7 | @@ -26,7 +26,7 @@ | ||
8 | # Build the memory leaking application. | ||
9 | c_src = 'test_tools_memleak_leaker_app.c' | ||
10 | tmp_dir = tempfile.mkdtemp(prefix='bcc-test-memleak-') | ||
11 | - c_src_full = os.path.dirname(sys.argv[0]) + os.path.sep + c_src | ||
12 | + c_src_full = os.path.abspath(os.path.dirname(sys.argv[0])) + os.path.sep + c_src | ||
13 | exec_dst = tmp_dir + os.path.sep + 'leaker_app' | ||
14 | |||
15 | if subprocess.call(['gcc', '-g', '-O0', '-o', exec_dst, c_src_full]) != 0: | ||
16 | |||
diff --git a/meta-oe/dynamic-layers/meta-python/recipes-devtools/bcc/bcc/ptest_wrapper.sh b/meta-oe/dynamic-layers/meta-python/recipes-devtools/bcc/bcc/ptest_wrapper.sh new file mode 100644 index 0000000000..92d015614c --- /dev/null +++ b/meta-oe/dynamic-layers/meta-python/recipes-devtools/bcc/bcc/ptest_wrapper.sh | |||
@@ -0,0 +1,16 @@ | |||
1 | #!/bin/sh | ||
2 | # Simple OE specific wrapper for bcc python tests | ||
3 | |||
4 | name=$1 | ||
5 | kind=$2 | ||
6 | cmd=$3 | ||
7 | shift 3 | ||
8 | |||
9 | case $kind in | ||
10 | simple|sudo) | ||
11 | $cmd "$@" | ||
12 | ;; | ||
13 | *) | ||
14 | echo "Invalid kind $kind of test $name" | ||
15 | exit 1 | ||
16 | esac | ||
diff --git a/meta-oe/dynamic-layers/meta-python/recipes-devtools/bcc/bcc/run-ptest b/meta-oe/dynamic-layers/meta-python/recipes-devtools/bcc/bcc/run-ptest new file mode 100644 index 0000000000..4740ae9c11 --- /dev/null +++ b/meta-oe/dynamic-layers/meta-python/recipes-devtools/bcc/bcc/run-ptest | |||
@@ -0,0 +1,65 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | cd tests || exit 1 | ||
4 | |||
5 | PASS_CNT=0 | ||
6 | FAIL_CNT=0 | ||
7 | FAILED="" | ||
8 | |||
9 | print_test_result() { | ||
10 | if [ $? -eq 0 ]; then | ||
11 | echo PASS: "$1" | ||
12 | PASS_CNT=$((PASS_CNT + 1)) | ||
13 | else | ||
14 | echo FAIL: "$1" | ||
15 | FAIL_CNT=$((FAIL_CNT + 1)) | ||
16 | FAILED="$FAILED $1;" | ||
17 | fi | ||
18 | } | ||
19 | |||
20 | ARCH=$(uname -m) | ||
21 | |||
22 | case "$ARCH" in | ||
23 | x86_64) | ||
24 | KDIR="x86" | ||
25 | ;; | ||
26 | riscv64) | ||
27 | KDIR="riscv" | ||
28 | ;; | ||
29 | aarch64) | ||
30 | KDIR="arm64" | ||
31 | ;; | ||
32 | powerpc64le | ppc64le) | ||
33 | KDIR="powerpc" | ||
34 | ;; | ||
35 | *) | ||
36 | echo "Architecture not present, Add the architecture in run-ptest: $ARCH" | ||
37 | exit 1 | ||
38 | ;; | ||
39 | esac | ||
40 | |||
41 | export BCC_KERNEL_SOURCE="/usr/src/kernel/arch/$KDIR" | ||
42 | |||
43 | # Run CC tests, set IFS as test names have spaces | ||
44 | IFS=$(printf '\n\t') | ||
45 | for test_name in $(./cc/test_libbcc_no_libbpf --list-test-names-only); do | ||
46 | ./cc/test_libbcc_no_libbpf "$test_name" > /dev/null 2>&1 | ||
47 | print_test_result "cc $test_name" | ||
48 | done | ||
49 | unset IFS | ||
50 | |||
51 | # Run python tests, skip namespace tests as they currently don't work | ||
52 | if cmake -DCMAKE_TESTING_ENABLED=ON -DTEST_WRAPPER="$(pwd)/ptest_wrapper.sh" python > /dev/null 2>&1; then | ||
53 | for test_name in $(awk -F '[( ]' '/^add_test/ && !/namespace/ {print $2}' CTestTestfile.cmake); do | ||
54 | ctest -Q -R "$test_name" | ||
55 | print_test_result "python $test_name" | ||
56 | done | ||
57 | else | ||
58 | print_test_result "cmake error, couldn't start python tests" | ||
59 | fi | ||
60 | |||
61 | echo "#### bcc tests summary ####" | ||
62 | echo "# TOTAL: $((PASS_CNT + FAIL_CNT))" | ||
63 | echo "# PASS: $PASS_CNT" | ||
64 | echo "# FAIL: $FAIL_CNT ($FAILED)" | ||
65 | echo "###########################" | ||
diff --git a/meta-oe/dynamic-layers/meta-python/recipes-devtools/bcc/bcc_0.35.0.bb b/meta-oe/dynamic-layers/meta-python/recipes-devtools/bcc/bcc_0.35.0.bb new file mode 100644 index 0000000000..b810f6ec77 --- /dev/null +++ b/meta-oe/dynamic-layers/meta-python/recipes-devtools/bcc/bcc_0.35.0.bb | |||
@@ -0,0 +1,92 @@ | |||
1 | SUMMARY = "BPF Compiler Collection (BCC)" | ||
2 | HOMEPAGE = "https://github.com/iovisor/bcc" | ||
3 | LICENSE = "Apache-2.0" | ||
4 | LIC_FILES_CHKSUM = "file://LICENSE.txt;md5=e3fc50a88d0a364313df4b21ef20c29e" | ||
5 | |||
6 | inherit cmake python3native manpages ptest | ||
7 | |||
8 | DEPENDS += "bison-native \ | ||
9 | flex-native \ | ||
10 | zip-native \ | ||
11 | flex \ | ||
12 | elfutils \ | ||
13 | clang \ | ||
14 | libbpf \ | ||
15 | python3-setuptools-native \ | ||
16 | " | ||
17 | |||
18 | RDEPENDS:${PN} += "bash python3 python3-core python3-setuptools xz" | ||
19 | RDEPENDS:${PN}-ptest = "kernel-devsrc packagegroup-core-buildessential cmake bash python3 python3-netaddr python3-pyroute2" | ||
20 | |||
21 | SRC_URI = "gitsm://github.com/iovisor/bcc;branch=master;protocol=https;tag=v${PV} \ | ||
22 | file://0001-CMakeLists.txt-override-the-PY_CMD_ESCAPED.patch \ | ||
23 | file://0001-Vendor-just-enough-extra-headers-to-allow-libbpf-to-.patch \ | ||
24 | file://run-ptest \ | ||
25 | file://ptest_wrapper.sh \ | ||
26 | file://fix_for_memleak.patch \ | ||
27 | " | ||
28 | |||
29 | SRCREV = "c31a1ca305f787ba53e001ead45ebf65233a32cf" | ||
30 | |||
31 | PACKAGECONFIG ??= "examples" | ||
32 | PACKAGECONFIG:remove:libc-musl = "examples" | ||
33 | |||
34 | PACKAGECONFIG[manpages] = "-DENABLE_MAN=ON,-DENABLE_MAN=OFF," | ||
35 | PACKAGECONFIG[examples] = "-DENABLE_EXAMPLES=ON,-DENABLE_EXAMPLES=OFF," | ||
36 | |||
37 | EXTRA_OECMAKE = " \ | ||
38 | -DREVISION='${PV}' \ | ||
39 | -DCMAKE_USE_LIBBPF_PACKAGE=ON \ | ||
40 | -DENABLE_LLVM_SHARED=ON \ | ||
41 | -DENABLE_CLANG_JIT=ON \ | ||
42 | -DPY_SKIP_DEB_LAYOUT=ON \ | ||
43 | -DPYTHON_CMD=${PYTHON} \ | ||
44 | -DPYTHON_FLAGS=--install-lib=${PYTHON_SITEPACKAGES_DIR} \ | ||
45 | " | ||
46 | |||
47 | # Avoid stripping debuginfo.so to fix some tests. | ||
48 | INHIBIT_PACKAGE_STRIP = "1" | ||
49 | INHIBIT_PACKAGE_DEBUG_SPLIT = "1" | ||
50 | |||
51 | do_install:append() { | ||
52 | sed -e 's@#!/usr/bin/env python@#!/usr/bin/env python3@g' \ | ||
53 | -i $(find ${D}${datadir}/${PN} -type f) | ||
54 | sed -e 's@#!/usr/bin/python.*@#!/usr/bin/env python3@g' \ | ||
55 | -i $(find ${D}${datadir}/${PN} -type f) | ||
56 | rm -rf ${D}${datadir}/bcc/examples/lua | ||
57 | } | ||
58 | |||
59 | do_install_ptest() { | ||
60 | install -d ${D}${PTEST_PATH}/tests/cc | ||
61 | # ptest searches for shared libs and archive files in the build folder. | ||
62 | # Hence, these files are copied to the image to fix these tests. | ||
63 | install -d ${D}${B}/tests/cc | ||
64 | install ${B}/tests/cc/archive.zip ${B}/tests/cc/libdebuginfo_test_lib.so ${B}/tests/cc/with_gnu_debuglink.so ${B}/tests/cc/with_gnu_debugdata.so ${B}/tests/cc/debuginfo.so ${D}${B}/tests/cc | ||
65 | install -d ${D}/opt | ||
66 | install ${B}/tests/cc/test_libbcc_no_libbpf ${B}/tests/cc/libusdt_test_lib.so ${D}${PTEST_PATH}/tests/cc | ||
67 | cp -rf ${S}/tests/python ${D}${PTEST_PATH}/tests/python | ||
68 | install ${UNPACKDIR}/ptest_wrapper.sh ${D}${PTEST_PATH}/tests | ||
69 | install ${S}/examples/networking/simulation.py ${D}${PTEST_PATH}/tests/python | ||
70 | find ${S}/tools/ -type f -name "*.py" -exec \ | ||
71 | sed -i \ | ||
72 | -e 's@^#! */usr/bin/env python$@#!/usr/bin/env python3@' \ | ||
73 | -e 's@^#! */usr/bin/python.*@#!/usr/bin/env python3@' {} + | ||
74 | cp -rf ${S}/tools/ ${D}${PTEST_PATH}/../../tools/ | ||
75 | } | ||
76 | |||
77 | FILES:${PN} += "${PYTHON_SITEPACKAGES_DIR}" | ||
78 | FILES:${PN} += "${B}/tests/cc" | ||
79 | FILES:${PN}-ptest += "${libdir}/libbcc.so" | ||
80 | FILES:${PN}-ptest += "${libdir}/tools/" | ||
81 | FILES:${PN}-ptest += "/opt/" | ||
82 | FILES:${PN}-doc += "${datadir}/${PN}/man" | ||
83 | |||
84 | COMPATIBLE_HOST = "(x86_64.*|aarch64.*|powerpc64.*|riscv64.*)-linux" | ||
85 | |||
86 | # WARNING: bcc-0.30.0+git-r0 do_package_qa: QA Issue: File /usr/lib/bcc/ptest/tests/cc/test_libbcc_no_libbpf in package bcc-ptest contains reference to TMPDIR [buildpaths] | ||
87 | # this one is difficult to resolve, because the tests use CMAKE_CURRENT_BINARY_DIR directly in .cc e.g.: | ||
88 | # https://github.com/iovisor/bcc/commit/7271bfc946a19413761be2e3c60c48bf72c5eea1#diff-233a0bfa490f3d7466c49935b64c86dd93956bbc0461f5af703b344cf6601461 | ||
89 | # we would probably need to use separate variable for "runtime" path for test assets from the standard CMAKE_CURRENT_BINARY_DIR variable or use relative | ||
90 | # path from the test binary | ||
91 | WARN_QA:append = "${@bb.utils.contains('PTEST_ENABLED', '1', ' buildpaths', '', d)}" | ||
92 | ERROR_QA:remove = "${@bb.utils.contains('PTEST_ENABLED', '1', 'buildpaths', '', d)}" | ||
diff --git a/meta-oe/dynamic-layers/meta-python/recipes-devtools/bpftrace/bpftrace/0001-Fix-build-failures-due-to-missing-location.hh.patch b/meta-oe/dynamic-layers/meta-python/recipes-devtools/bpftrace/bpftrace/0001-Fix-build-failures-due-to-missing-location.hh.patch new file mode 100644 index 0000000000..1c2ae33238 --- /dev/null +++ b/meta-oe/dynamic-layers/meta-python/recipes-devtools/bpftrace/bpftrace/0001-Fix-build-failures-due-to-missing-location.hh.patch | |||
@@ -0,0 +1,54 @@ | |||
1 | From 24421ba92c69f1abaadaff01270621917616a2b8 Mon Sep 17 00:00:00 2001 | ||
2 | From: Changqing Li <changqing.li@windriver.com> | ||
3 | Date: Thu, 17 Apr 2025 10:38:50 +0800 | ||
4 | Subject: [PATCH] Fix build failures due to missing location.hh | ||
5 | |||
6 | ast/location.h does `#include "location.hh"` and location.hh is | ||
7 | generated by the parser so any CMake target whose source includes | ||
8 | ast/location.h needs to have a dependency on the `parser` target, | ||
9 | otherwise the compilation may fail due to incorrect ordering of build | ||
10 | targets. This also applies to targets which include ast/location.h | ||
11 | transitively via other headers. | ||
12 | |||
13 | To avoid such errors, do 2 things: | ||
14 | - drop includes of ast/location.h where unused | ||
15 | - for CMake targets including ast/location.h, add an explicit dependency | ||
16 | on the `parser` target | ||
17 | |||
18 | Signed-off-by: Viktor Malik <viktor.malik@gmail.com> | ||
19 | |||
20 | Upstream-Status: Backport [https://github.com/bpftrace/bpftrace/commit/743cb9c88c25fb9737d714f4d4ac853f05bb6481] | ||
21 | |||
22 | Signed-off-by: Changqing Li <changqing.li@windriver.com> | ||
23 | --- | ||
24 | src/CMakeLists.txt | 1 + | ||
25 | src/ast/CMakeLists.txt | 1 + | ||
26 | 2 files changed, 2 insertions(+) | ||
27 | |||
28 | diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt | ||
29 | index e04ee429..13a51040 100644 | ||
30 | --- a/src/CMakeLists.txt | ||
31 | +++ b/src/CMakeLists.txt | ||
32 | @@ -21,6 +21,7 @@ add_library(compiler_core STATIC | ||
33 | struct.cpp | ||
34 | types.cpp | ||
35 | ) | ||
36 | +add_dependencies(compiler_core parser) | ||
37 | |||
38 | add_library(runtime STATIC | ||
39 | attached_probe.cpp | ||
40 | diff --git a/src/ast/CMakeLists.txt b/src/ast/CMakeLists.txt | ||
41 | index 92231f85..7230cf71 100644 | ||
42 | --- a/src/ast/CMakeLists.txt | ||
43 | +++ b/src/ast/CMakeLists.txt | ||
44 | @@ -22,6 +22,7 @@ add_library(ast STATIC | ||
45 | passes/return_path_analyser.cpp | ||
46 | ) | ||
47 | |||
48 | +add_dependencies(ast parser) | ||
49 | target_compile_definitions(ast PRIVATE ${BPFTRACE_FLAGS}) | ||
50 | target_link_libraries(ast PUBLIC ast_defs arch compiler_core parser) | ||
51 | |||
52 | -- | ||
53 | 2.34.1 | ||
54 | |||
diff --git a/meta-oe/dynamic-layers/meta-python/recipes-devtools/bpftrace/bpftrace/0002-CMakeLists.txt-allow-to-set-BISON_FLAGS-like-l.patch b/meta-oe/dynamic-layers/meta-python/recipes-devtools/bpftrace/bpftrace/0002-CMakeLists.txt-allow-to-set-BISON_FLAGS-like-l.patch new file mode 100644 index 0000000000..4f0ebbf564 --- /dev/null +++ b/meta-oe/dynamic-layers/meta-python/recipes-devtools/bpftrace/bpftrace/0002-CMakeLists.txt-allow-to-set-BISON_FLAGS-like-l.patch | |||
@@ -0,0 +1,38 @@ | |||
1 | From ce5d908bb1256ede680fbfd521f087060a567dca Mon Sep 17 00:00:00 2001 | ||
2 | From: Martin Jansa <martin.jansa@gmail.com> | ||
3 | Date: Tue, 3 Sep 2024 14:17:51 +0200 | ||
4 | Subject: [PATCH] CMakeLists.txt: allow to set BISON_FLAGS like -l | ||
5 | |||
6 | Signed-off-by: Martin Jansa <martin.jansa@gmail.com> | ||
7 | |||
8 | Upstream-Status: Pending | ||
9 | --- | ||
10 | CMakeLists.txt | 10 +++++++--- | ||
11 | 1 file changed, 7 insertions(+), 3 deletions(-) | ||
12 | |||
13 | --- a/CMakeLists.txt | ||
14 | +++ b/CMakeLists.txt | ||
15 | @@ -100,16 +100,20 @@ include_directories(SYSTEM ${LIBCEREAL_I | ||
16 | |||
17 | find_package(BISON REQUIRED) | ||
18 | find_package(FLEX REQUIRED) | ||
19 | + | ||
20 | +# avoid buildpaths in generated #line statements and allow to pass --file-prefix-map=OLD=NEW | ||
21 | +set(BISON_FLAGS "${BISON_FLAGS} -l") | ||
22 | +set(FLEX_FLAGS "${FLEX_FLAGS} -L") | ||
23 | # `parser_class_name` is deprecated and generates warnings in bison >= 3.3. | ||
24 | # But `api.parser.class` is not supported in bison < 3.3. So we must inject | ||
25 | # the %define based on the bison version here. | ||
26 | if(${BISON_VERSION} VERSION_GREATER_EQUAL 3.3) | ||
27 | - set(BISON_FLAGS "-Dapi.parser.class={Parser}") | ||
28 | + set(BISON_FLAGS "${BISON_FLAGS} -Dapi.parser.class={Parser}") | ||
29 | else() | ||
30 | - set(BISON_FLAGS "-Dparser_class_name={Parser}") | ||
31 | + set(BISON_FLAGS "${BISON_FLAGS} -Dparser_class_name={Parser}") | ||
32 | endif() | ||
33 | bison_target(bison_parser src/parser.yy ${CMAKE_BINARY_DIR}/parser.tab.cc COMPILE_FLAGS ${BISON_FLAGS} VERBOSE) | ||
34 | -flex_target(flex_lexer src/lexer.l ${CMAKE_BINARY_DIR}/lex.yy.cc) | ||
35 | +flex_target(flex_lexer src/lexer.l ${CMAKE_BINARY_DIR}/lex.yy.cc COMPILE_FLAGS ${FLEX_FLAGS}) | ||
36 | add_flex_bison_dependency(flex_lexer bison_parser) | ||
37 | add_library(parser STATIC ${BISON_bison_parser_OUTPUTS} ${FLEX_flex_lexer_OUTPUTS}) | ||
38 | target_compile_options(parser PRIVATE "-w") | ||
diff --git a/meta-oe/dynamic-layers/meta-python/recipes-devtools/bpftrace/bpftrace/run-ptest b/meta-oe/dynamic-layers/meta-python/recipes-devtools/bpftrace/bpftrace/run-ptest new file mode 100644 index 0000000000..63d65e25a2 --- /dev/null +++ b/meta-oe/dynamic-layers/meta-python/recipes-devtools/bpftrace/bpftrace/run-ptest | |||
@@ -0,0 +1,51 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | # The whole test suite may take up to 40 minutes to run, so setting -t 2400 | ||
4 | # parameter in ptest-runner is necessary to not kill it before completion | ||
5 | |||
6 | cd tests || exit 1 | ||
7 | export BPFTRACE_RUNTIME_TEST_EXECUTABLE=/usr/bin/bpftrace | ||
8 | export BPFTRACE_AOT_RUNTIME_TEST_EXECUTABLE=/usr/bin/bpftrace-aotrt | ||
9 | |||
10 | PASS_CNT=0 | ||
11 | FAIL_CNT=0 | ||
12 | SKIP_CNT=0 | ||
13 | FAILED="" | ||
14 | |||
15 | print_test_result() { | ||
16 | if [ $? -eq 0 ]; then | ||
17 | echo "PASS: $1" | ||
18 | PASS_CNT=$((PASS_CNT + 1)) | ||
19 | else | ||
20 | echo "FAIL: $1" | ||
21 | FAIL_CNT=$((FAIL_CNT + 1)) | ||
22 | FAILED="${FAILED:+$FAILED }$1;" | ||
23 | fi | ||
24 | } | ||
25 | |||
26 | IFS=$(printf '\n\t') | ||
27 | # Start unit tests | ||
28 | for test_name in $(./bpftrace_test --gtest_list_tests | grep -v "^ "); do | ||
29 | ./bpftrace_test --gtest_filter="${test_name}*" > /dev/null 2>&1 | ||
30 | print_test_result "unit:$test_name" | ||
31 | done | ||
32 | |||
33 | # Start runtime tests | ||
34 | for test_name in $(ls runtime); do | ||
35 | # Ignore test cases that hang the suite forever (bpftrace v0.16.0) | ||
36 | if [ "$test_name" = "signals" ] || [ "$test_name" = "watchpoint" ]; then | ||
37 | echo "SKIP: runtime:$test_name" | ||
38 | SKIP_CNT=$((SKIP_CNT + 1)) | ||
39 | continue | ||
40 | fi | ||
41 | python3 runtime/engine/main.py --filter="${test_name}.*" > /dev/null 2>&1 | ||
42 | print_test_result "runtime:$test_name" | ||
43 | done | ||
44 | unset IFS | ||
45 | |||
46 | echo "#### bpftrace tests summary ####" | ||
47 | echo "# TOTAL: $((PASS_CNT + FAIL_CNT + SKIP_CNT))" | ||
48 | echo "# PASS: $PASS_CNT" | ||
49 | echo "# FAIL: $FAIL_CNT ($FAILED)" | ||
50 | echo "# SKIP: $SKIP_CNT" | ||
51 | echo "################################" | ||
diff --git a/meta-oe/dynamic-layers/meta-python/recipes-devtools/bpftrace/bpftrace_0.23.0.bb b/meta-oe/dynamic-layers/meta-python/recipes-devtools/bpftrace/bpftrace_0.23.0.bb new file mode 100644 index 0000000000..bd3b772220 --- /dev/null +++ b/meta-oe/dynamic-layers/meta-python/recipes-devtools/bpftrace/bpftrace_0.23.0.bb | |||
@@ -0,0 +1,62 @@ | |||
1 | SUMMARY = "bpftrace" | ||
2 | HOMEPAGE = "https://github.com/iovisor/bpftrace" | ||
3 | LICENSE = "Apache-2.0" | ||
4 | LIC_FILES_CHKSUM = "file://LICENSE;md5=3b83ef96387f14655fc854ddc3c6bd57" | ||
5 | |||
6 | DEPENDS += "bison-native \ | ||
7 | flex-native \ | ||
8 | gzip-native \ | ||
9 | elfutils \ | ||
10 | bcc \ | ||
11 | systemtap \ | ||
12 | libcereal \ | ||
13 | libbpf \ | ||
14 | " | ||
15 | DEPENDS += "${@bb.utils.contains('PTEST_ENABLED', '1', 'pahole-native llvm-native', '', d)}" | ||
16 | |||
17 | RDEPENDS:${PN} += "bash python3 xz" | ||
18 | |||
19 | PV .= "+git" | ||
20 | |||
21 | SRC_URI = "git://github.com/iovisor/bpftrace;branch=release/0.23.x;protocol=https \ | ||
22 | file://run-ptest \ | ||
23 | file://0002-CMakeLists.txt-allow-to-set-BISON_FLAGS-like-l.patch \ | ||
24 | file://0001-Fix-build-failures-due-to-missing-location.hh.patch \ | ||
25 | " | ||
26 | SRCREV = "01e806d24c61f996f1809e1e991646311499db4f" | ||
27 | |||
28 | inherit bash-completion cmake ptest pkgconfig | ||
29 | |||
30 | PACKAGECONFIG ?= " \ | ||
31 | ${@bb.utils.contains('PTEST_ENABLED', '1', 'tests', '', d)} \ | ||
32 | ${@bb.utils.contains("DISTRO_FEATURES", "systemd", "systemd", "", d)} \ | ||
33 | " | ||
34 | |||
35 | PACKAGECONFIG[tests] = "-DBUILD_TESTING=ON,-DBUILD_TESTING=OFF,gtest xxd-native" | ||
36 | PACKAGECONFIG[systemd] = "-DENABLE_SYSTEMD=ON,-DENABLE_SYSTEMD=OFF,systemd" | ||
37 | |||
38 | do_install_ptest() { | ||
39 | if [ -e ${B}/tests/bpftrace_test ]; then | ||
40 | install -Dm 755 ${B}/tests/bpftrace_test ${D}${PTEST_PATH}/tests/bpftrace_test | ||
41 | cp -rf ${B}/tests/runtime ${D}${PTEST_PATH}/tests | ||
42 | cp -rf ${B}/tests/test* ${D}${PTEST_PATH}/tests | ||
43 | fi | ||
44 | } | ||
45 | |||
46 | EXTRA_OECMAKE = " \ | ||
47 | -DCMAKE_ENABLE_EXPORTS=1 \ | ||
48 | -DCMAKE_BUILD_TYPE=Release \ | ||
49 | -DUSE_SYSTEM_BPF_BCC=ON \ | ||
50 | -DENABLE_MAN=OFF \ | ||
51 | -DBISON_FLAGS='--file-prefix-map=${WORKDIR}=' \ | ||
52 | " | ||
53 | |||
54 | COMPATIBLE_HOST = "(x86_64.*|aarch64.*|powerpc64.*|riscv64.*)-linux" | ||
55 | COMPATIBLE_HOST:libc-musl = "null" | ||
56 | |||
57 | INHIBIT_PACKAGE_STRIP_FILES += "\ | ||
58 | ${PKGD}${PTEST_PATH}/tests/testprogs/uprobe_test \ | ||
59 | " | ||
60 | |||
61 | WARN_QA:append = "${@bb.utils.contains('PTEST_ENABLED', '1', ' buildpaths', '', d)}" | ||
62 | ERROR_QA:remove = "${@bb.utils.contains('PTEST_ENABLED', '1', 'buildpaths', '', d)}" | ||