Re: [PATCH RFC 2/6] libbpf: Add BTF_KIND_FLOAT support
From: Andrii Nakryiko <hidden>
Date: 2021-02-11 00:16:55
On Tue, Feb 9, 2021 at 7:04 PM Ilya Leoshkevich [off-list ref] wrote:
The logic follows that of BTF_KIND_INT most of the time, some functions are even unified to work on both. Sanitization replaces BTF_KIND_FLOATs with equally-sized BTF_KIND_INTs on older kernels. Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com> --- tools/lib/bpf/btf.c | 85 +++++++++++++++++++++++---------- tools/lib/bpf/btf.h | 13 +++++ tools/lib/bpf/btf_dump.c | 4 ++ tools/lib/bpf/libbpf.c | 32 ++++++++++++- tools/lib/bpf/libbpf.map | 5 ++ tools/lib/bpf/libbpf_internal.h | 4 ++ 6 files changed, 118 insertions(+), 25 deletions(-)
[...]
quoted hunk ↗ jump to hunk
@@ -2445,6 +2450,12 @@ static void bpf_object__sanitize_btf(struct bpf_object *obj, struct btf *btf) } else if (!has_func_global && btf_is_func(t)) { /* replace BTF_FUNC_GLOBAL with BTF_FUNC_STATIC */ t->info = BTF_INFO_ENC(BTF_KIND_FUNC, 0, 0); + } else if (!has_float && btf_is_float(t)) { + /* replace FLOAT with INT */ + __u8 nr_bits = btf_float_bits(t); +
nit: no need for extra variable, just use it inline below
quoted hunk ↗ jump to hunk
+ t->info = BTF_INFO_ENC(BTF_KIND_INT, 0, 0); + *(int *)(t + 1) = BTF_INT_ENC(0, 0, nr_bits); } } }@@ -3882,6 +3893,18 @@ static int probe_kern_btf_datasec(void) strs, sizeof(strs))); }
[...]