mirror of
https://github.com/netdata/libbpf.git
synced 2026-04-06 00:29:07 +08:00
bpf: Rename BTF_KIND_TAG to BTF_KIND_DECL_TAG
Patch set [1] introduced BTF_KIND_TAG to allow tagging declarations for struct/union, struct/union field, var, func and func arguments and these tags will be encoded into dwarf. They are also encoded to btf by llvm for the bpf target. After BTF_KIND_TAG is introduced, we intended to use it for kernel __user attributes. But kernel __user is actually a type attribute. Upstream and internal discussion showed it is not a good idea to mix declaration attribute and type attribute. So we proposed to introduce btf_type_tag as a type attribute and existing btf_tag renamed to btf_decl_tag ([2]). This patch renamed BTF_KIND_TAG to BTF_KIND_DECL_TAG and some other declarations with *_tag to *_decl_tag to make it clear the tag is for declaration. In the future, BTF_KIND_TYPE_TAG might be introduced per [3]. [1] https://lore.kernel.org/bpf/20210914223004.244411-1-yhs@fb.com/ [2] https://reviews.llvm.org/D111588 [3] https://reviews.llvm.org/D111199 Fixes: b5ea834dde6b ("bpf: Support for new btf kind BTF_KIND_TAG") Fixes: 5b84bd10363e ("libbpf: Add support for BTF_KIND_TAG") Fixes: 5c07f2fec003 ("bpftool: Add support for BTF_KIND_TAG") Signed-off-by: Yonghong Song <yhs@fb.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://lore.kernel.org/bpf/20211012164838.3345699-1-yhs@fb.com
This commit is contained in:
committed by
Andrii Nakryiko
parent
ebf17ac628
commit
0f3ba10651
24
src/libbpf.c
24
src/libbpf.c
@@ -195,8 +195,8 @@ enum kern_feature_id {
|
||||
FEAT_BTF_FLOAT,
|
||||
/* BPF perf link support */
|
||||
FEAT_PERF_LINK,
|
||||
/* BTF_KIND_TAG support */
|
||||
FEAT_BTF_TAG,
|
||||
/* BTF_KIND_DECL_TAG support */
|
||||
FEAT_BTF_DECL_TAG,
|
||||
__FEAT_CNT,
|
||||
};
|
||||
|
||||
@@ -2024,7 +2024,7 @@ static const char *__btf_kind_str(__u16 kind)
|
||||
case BTF_KIND_VAR: return "var";
|
||||
case BTF_KIND_DATASEC: return "datasec";
|
||||
case BTF_KIND_FLOAT: return "float";
|
||||
case BTF_KIND_TAG: return "tag";
|
||||
case BTF_KIND_DECL_TAG: return "decl_tag";
|
||||
default: return "unknown";
|
||||
}
|
||||
}
|
||||
@@ -2524,9 +2524,9 @@ static bool btf_needs_sanitization(struct bpf_object *obj)
|
||||
bool has_datasec = kernel_supports(obj, FEAT_BTF_DATASEC);
|
||||
bool has_float = kernel_supports(obj, FEAT_BTF_FLOAT);
|
||||
bool has_func = kernel_supports(obj, FEAT_BTF_FUNC);
|
||||
bool has_tag = kernel_supports(obj, FEAT_BTF_TAG);
|
||||
bool has_decl_tag = kernel_supports(obj, FEAT_BTF_DECL_TAG);
|
||||
|
||||
return !has_func || !has_datasec || !has_func_global || !has_float || !has_tag;
|
||||
return !has_func || !has_datasec || !has_func_global || !has_float || !has_decl_tag;
|
||||
}
|
||||
|
||||
static void bpf_object__sanitize_btf(struct bpf_object *obj, struct btf *btf)
|
||||
@@ -2535,15 +2535,15 @@ static void bpf_object__sanitize_btf(struct bpf_object *obj, struct btf *btf)
|
||||
bool has_datasec = kernel_supports(obj, FEAT_BTF_DATASEC);
|
||||
bool has_float = kernel_supports(obj, FEAT_BTF_FLOAT);
|
||||
bool has_func = kernel_supports(obj, FEAT_BTF_FUNC);
|
||||
bool has_tag = kernel_supports(obj, FEAT_BTF_TAG);
|
||||
bool has_decl_tag = kernel_supports(obj, FEAT_BTF_DECL_TAG);
|
||||
struct btf_type *t;
|
||||
int i, j, vlen;
|
||||
|
||||
for (i = 1; i <= btf__get_nr_types(btf); i++) {
|
||||
t = (struct btf_type *)btf__type_by_id(btf, i);
|
||||
|
||||
if ((!has_datasec && btf_is_var(t)) || (!has_tag && btf_is_tag(t))) {
|
||||
/* replace VAR/TAG with INT */
|
||||
if ((!has_datasec && btf_is_var(t)) || (!has_decl_tag && btf_is_decl_tag(t))) {
|
||||
/* replace VAR/DECL_TAG with INT */
|
||||
t->info = BTF_INFO_ENC(BTF_KIND_INT, 0, 0);
|
||||
/*
|
||||
* using size = 1 is the safest choice, 4 will be too
|
||||
@@ -4248,7 +4248,7 @@ static int probe_kern_btf_float(void)
|
||||
strs, sizeof(strs)));
|
||||
}
|
||||
|
||||
static int probe_kern_btf_tag(void)
|
||||
static int probe_kern_btf_decl_tag(void)
|
||||
{
|
||||
static const char strs[] = "\0tag";
|
||||
__u32 types[] = {
|
||||
@@ -4258,7 +4258,7 @@ static int probe_kern_btf_tag(void)
|
||||
BTF_TYPE_ENC(1, BTF_INFO_ENC(BTF_KIND_VAR, 0, 0), 1),
|
||||
BTF_VAR_STATIC,
|
||||
/* attr */
|
||||
BTF_TYPE_TAG_ENC(1, 2, -1),
|
||||
BTF_TYPE_DECL_TAG_ENC(1, 2, -1),
|
||||
};
|
||||
|
||||
return probe_fd(libbpf__load_raw_btf((char *)types, sizeof(types),
|
||||
@@ -4481,8 +4481,8 @@ static struct kern_feature_desc {
|
||||
[FEAT_PERF_LINK] = {
|
||||
"BPF perf link support", probe_perf_link,
|
||||
},
|
||||
[FEAT_BTF_TAG] = {
|
||||
"BTF_KIND_TAG support", probe_kern_btf_tag,
|
||||
[FEAT_BTF_DECL_TAG] = {
|
||||
"BTF_KIND_DECL_TAG support", probe_kern_btf_decl_tag,
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user