summaryrefslogtreecommitdiffstats
path: root/dynamic-layers
diff options
context:
space:
mode:
authorDaniel Thompson <daniel@redfelineninja.org.uk>2022-05-19 09:23:45 +0000
committerKhem Raj <raj.khem@gmail.com>2022-05-27 11:54:02 -0700
commit229e28a6a061cb78d9f31c253ee8e741a093ab8d (patch)
tree76b52262944583cbfd467e83c7692d0bbb975895 /dynamic-layers
parenta49a75be369d564e3d641216add16277537aac85 (diff)
downloadmeta-clang-229e28a6a061cb78d9f31c253ee8e741a093ab8d.tar.gz
bcc: Fixes to allow libbpf to be de-vendored
De-vendoring libbpf resolves a SEGV everytime we run bpftrace. Unfortunately it is not currently possible to de-vendor libbpf because bcc does not build. Fix this with brute force and ignorance... and in a seperate patch so this can be treated as an explanation of the problem and ripped out in favour of the right fix. Signed-off-by: Daniel Thompson <daniel.thompson@linaro.org>
Diffstat (limited to 'dynamic-layers')
-rw-r--r--dynamic-layers/openembedded-layer/recipes-devtools/bcc/bcc/0001-Vendor-just-enough-extra-headers-to-allow-libbpf-to-.patch124
-rw-r--r--dynamic-layers/openembedded-layer/recipes-devtools/bcc/bcc_0.24.0.bb1
2 files changed, 125 insertions, 0 deletions
diff --git a/dynamic-layers/openembedded-layer/recipes-devtools/bcc/bcc/0001-Vendor-just-enough-extra-headers-to-allow-libbpf-to-.patch b/dynamic-layers/openembedded-layer/recipes-devtools/bcc/bcc/0001-Vendor-just-enough-extra-headers-to-allow-libbpf-to-.patch
new file mode 100644
index 0000000..946787c
--- /dev/null
+++ b/dynamic-layers/openembedded-layer/recipes-devtools/bcc/bcc/0001-Vendor-just-enough-extra-headers-to-allow-libbpf-to-.patch
@@ -0,0 +1,124 @@
1From 6cffc195eca6b53a12865d325ff97e7b5ba8f22b Mon Sep 17 00:00:00 2001
2From: Daniel Thompson <daniel.thompson@linaro.org>
3Date: Thu, 19 May 2022 09:14:20 +0000
4Subject: [PATCH] Vendor just enough extra headers to allow libbpf to be
5 de-vendored
6
7Currently it is not possible to build the bcc recipe when we de-vendor
8libbpf and adopt the packaged version. Ironically this is due to the
9deliberate vendoring of some depreciated btf code that is being removed
10upstream because bcc was the only user! In other words the vendored code
11doesn't work the de-vendored libbpf because also ends up de-vendoring
12one of the Linux uapi headers.
13
14This is obviously an OE specific issue (due to the current combination
15of linux headers, libbpf and bcc). It's a bit of a mess and the right
16solution is probably to update the system UAPI headers but I am committing
17this for now simply so I can easily show why we must de-vendor libbpf in
18the first place!
19
20Upstream-status: Inappropriate [other]
21
22Signed-off-by: Daniel Thompson <daniel.thompson@linaro.org>
23---
24 src/cc/bcc_btf.cc | 87 +++++++++++++++++++++++++++++++++++++++++++++++
25 1 file changed, 87 insertions(+)
26
27diff --git a/src/cc/bcc_btf.cc b/src/cc/bcc_btf.cc
28index 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/dynamic-layers/openembedded-layer/recipes-devtools/bcc/bcc_0.24.0.bb b/dynamic-layers/openembedded-layer/recipes-devtools/bcc/bcc_0.24.0.bb
index 9ad2d01..b5e3fe3 100644
--- a/dynamic-layers/openembedded-layer/recipes-devtools/bcc/bcc_0.24.0.bb
+++ b/dynamic-layers/openembedded-layer/recipes-devtools/bcc/bcc_0.24.0.bb
@@ -24,6 +24,7 @@ SRC_URI = "gitsm://github.com/iovisor/bcc;branch=master;protocol=https \
24 file://0001-python-CMakeLists.txt-Remove-check-for-host-etc-debi.patch \ 24 file://0001-python-CMakeLists.txt-Remove-check-for-host-etc-debi.patch \
25 file://0001-tools-trace.py-Fix-failing-to-exit.patch \ 25 file://0001-tools-trace.py-Fix-failing-to-exit.patch \
26 file://0001-CMakeLists.txt-override-the-PY_CMD_ESCAPED.patch \ 26 file://0001-CMakeLists.txt-override-the-PY_CMD_ESCAPED.patch \
27 file://0001-Vendor-just-enough-extra-headers-to-allow-libbpf-to-.patch \
27 " 28 "
28 29
29SRCREV = "8f40d6f57a8d94e7aee74ce358572d34d31b4ed4" 30SRCREV = "8f40d6f57a8d94e7aee74ce358572d34d31b4ed4"