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:b5ea834dde
("bpf: Support for new btf kind BTF_KIND_TAG") Fixes:5b84bd1036
("libbpf: Add support for BTF_KIND_TAG") Fixes:5c07f2fec0
("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:
parent
431bfb9ee3
commit
223f903e9c
@ -85,7 +85,7 @@ sequentially and type id is assigned to each recognized type starting from id
|
||||
#define BTF_KIND_VAR 14 /* Variable */
|
||||
#define BTF_KIND_DATASEC 15 /* Section */
|
||||
#define BTF_KIND_FLOAT 16 /* Floating point */
|
||||
#define BTF_KIND_TAG 17 /* Tag */
|
||||
#define BTF_KIND_DECL_TAG 17 /* Decl Tag */
|
||||
|
||||
Note that the type section encodes debug info, not just pure types.
|
||||
``BTF_KIND_FUNC`` is not a type, and it represents a defined subprogram.
|
||||
@ -107,7 +107,7 @@ Each type contains the following common data::
|
||||
* "size" tells the size of the type it is describing.
|
||||
*
|
||||
* "type" is used by PTR, TYPEDEF, VOLATILE, CONST, RESTRICT,
|
||||
* FUNC, FUNC_PROTO and TAG.
|
||||
* FUNC, FUNC_PROTO and DECL_TAG.
|
||||
* "type" is a type_id referring to another type.
|
||||
*/
|
||||
union {
|
||||
@ -466,30 +466,30 @@ map definition.
|
||||
|
||||
No additional type data follow ``btf_type``.
|
||||
|
||||
2.2.17 BTF_KIND_TAG
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
2.2.17 BTF_KIND_DECL_TAG
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
``struct btf_type`` encoding requirement:
|
||||
* ``name_off``: offset to a non-empty string
|
||||
* ``info.kind_flag``: 0
|
||||
* ``info.kind``: BTF_KIND_TAG
|
||||
* ``info.kind``: BTF_KIND_DECL_TAG
|
||||
* ``info.vlen``: 0
|
||||
* ``type``: ``struct``, ``union``, ``func`` or ``var``
|
||||
|
||||
``btf_type`` is followed by ``struct btf_tag``.::
|
||||
``btf_type`` is followed by ``struct btf_decl_tag``.::
|
||||
|
||||
struct btf_tag {
|
||||
struct btf_decl_tag {
|
||||
__u32 component_idx;
|
||||
};
|
||||
|
||||
The ``name_off`` encodes btf_tag attribute string.
|
||||
The ``name_off`` encodes btf_decl_tag attribute string.
|
||||
The ``type`` should be ``struct``, ``union``, ``func`` or ``var``.
|
||||
For ``var`` type, ``btf_tag.component_idx`` must be ``-1``.
|
||||
For the other three types, if the btf_tag attribute is
|
||||
For ``var`` type, ``btf_decl_tag.component_idx`` must be ``-1``.
|
||||
For the other three types, if the btf_decl_tag attribute is
|
||||
applied to the ``struct``, ``union`` or ``func`` itself,
|
||||
``btf_tag.component_idx`` must be ``-1``. Otherwise,
|
||||
``btf_decl_tag.component_idx`` must be ``-1``. Otherwise,
|
||||
the attribute is applied to a ``struct``/``union`` member or
|
||||
a ``func`` argument, and ``btf_tag.component_idx`` should be a
|
||||
a ``func`` argument, and ``btf_decl_tag.component_idx`` should be a
|
||||
valid index (starting from 0) pointing to a member or an argument.
|
||||
|
||||
3. BTF Kernel API
|
||||
|
@ -43,7 +43,7 @@ struct btf_type {
|
||||
* "size" tells the size of the type it is describing.
|
||||
*
|
||||
* "type" is used by PTR, TYPEDEF, VOLATILE, CONST, RESTRICT,
|
||||
* FUNC, FUNC_PROTO, VAR and TAG.
|
||||
* FUNC, FUNC_PROTO, VAR and DECL_TAG.
|
||||
* "type" is a type_id referring to another type.
|
||||
*/
|
||||
union {
|
||||
@ -74,7 +74,7 @@ enum {
|
||||
BTF_KIND_VAR = 14, /* Variable */
|
||||
BTF_KIND_DATASEC = 15, /* Section */
|
||||
BTF_KIND_FLOAT = 16, /* Floating point */
|
||||
BTF_KIND_TAG = 17, /* Tag */
|
||||
BTF_KIND_DECL_TAG = 17, /* Decl Tag */
|
||||
|
||||
NR_BTF_KINDS,
|
||||
BTF_KIND_MAX = NR_BTF_KINDS - 1,
|
||||
@ -174,14 +174,14 @@ struct btf_var_secinfo {
|
||||
__u32 size;
|
||||
};
|
||||
|
||||
/* BTF_KIND_TAG is followed by a single "struct btf_tag" to describe
|
||||
/* BTF_KIND_DECL_TAG is followed by a single "struct btf_decl_tag" to describe
|
||||
* additional information related to the tag applied location.
|
||||
* If component_idx == -1, the tag is applied to a struct, union,
|
||||
* variable or function. Otherwise, it is applied to a struct/union
|
||||
* member or a func argument, and component_idx indicates which member
|
||||
* or argument (0 ... vlen-1).
|
||||
*/
|
||||
struct btf_tag {
|
||||
struct btf_decl_tag {
|
||||
__s32 component_idx;
|
||||
};
|
||||
|
||||
|
@ -281,7 +281,7 @@ static const char * const btf_kind_str[NR_BTF_KINDS] = {
|
||||
[BTF_KIND_VAR] = "VAR",
|
||||
[BTF_KIND_DATASEC] = "DATASEC",
|
||||
[BTF_KIND_FLOAT] = "FLOAT",
|
||||
[BTF_KIND_TAG] = "TAG",
|
||||
[BTF_KIND_DECL_TAG] = "DECL_TAG",
|
||||
};
|
||||
|
||||
const char *btf_type_str(const struct btf_type *t)
|
||||
@ -460,12 +460,12 @@ static bool btf_type_is_datasec(const struct btf_type *t)
|
||||
return BTF_INFO_KIND(t->info) == BTF_KIND_DATASEC;
|
||||
}
|
||||
|
||||
static bool btf_type_is_tag(const struct btf_type *t)
|
||||
static bool btf_type_is_decl_tag(const struct btf_type *t)
|
||||
{
|
||||
return BTF_INFO_KIND(t->info) == BTF_KIND_TAG;
|
||||
return BTF_INFO_KIND(t->info) == BTF_KIND_DECL_TAG;
|
||||
}
|
||||
|
||||
static bool btf_type_is_tag_target(const struct btf_type *t)
|
||||
static bool btf_type_is_decl_tag_target(const struct btf_type *t)
|
||||
{
|
||||
return btf_type_is_func(t) || btf_type_is_struct(t) ||
|
||||
btf_type_is_var(t);
|
||||
@ -549,7 +549,7 @@ const struct btf_type *btf_type_resolve_func_ptr(const struct btf *btf,
|
||||
static bool btf_type_is_resolve_source_only(const struct btf_type *t)
|
||||
{
|
||||
return btf_type_is_var(t) ||
|
||||
btf_type_is_tag(t) ||
|
||||
btf_type_is_decl_tag(t) ||
|
||||
btf_type_is_datasec(t);
|
||||
}
|
||||
|
||||
@ -576,7 +576,7 @@ static bool btf_type_needs_resolve(const struct btf_type *t)
|
||||
btf_type_is_struct(t) ||
|
||||
btf_type_is_array(t) ||
|
||||
btf_type_is_var(t) ||
|
||||
btf_type_is_tag(t) ||
|
||||
btf_type_is_decl_tag(t) ||
|
||||
btf_type_is_datasec(t);
|
||||
}
|
||||
|
||||
@ -630,9 +630,9 @@ static const struct btf_var *btf_type_var(const struct btf_type *t)
|
||||
return (const struct btf_var *)(t + 1);
|
||||
}
|
||||
|
||||
static const struct btf_tag *btf_type_tag(const struct btf_type *t)
|
||||
static const struct btf_decl_tag *btf_type_decl_tag(const struct btf_type *t)
|
||||
{
|
||||
return (const struct btf_tag *)(t + 1);
|
||||
return (const struct btf_decl_tag *)(t + 1);
|
||||
}
|
||||
|
||||
static const struct btf_kind_operations *btf_type_ops(const struct btf_type *t)
|
||||
@ -3820,11 +3820,11 @@ static const struct btf_kind_operations float_ops = {
|
||||
.show = btf_df_show,
|
||||
};
|
||||
|
||||
static s32 btf_tag_check_meta(struct btf_verifier_env *env,
|
||||
static s32 btf_decl_tag_check_meta(struct btf_verifier_env *env,
|
||||
const struct btf_type *t,
|
||||
u32 meta_left)
|
||||
{
|
||||
const struct btf_tag *tag;
|
||||
const struct btf_decl_tag *tag;
|
||||
u32 meta_needed = sizeof(*tag);
|
||||
s32 component_idx;
|
||||
const char *value;
|
||||
@ -3852,7 +3852,7 @@ static s32 btf_tag_check_meta(struct btf_verifier_env *env,
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
component_idx = btf_type_tag(t)->component_idx;
|
||||
component_idx = btf_type_decl_tag(t)->component_idx;
|
||||
if (component_idx < -1) {
|
||||
btf_verifier_log_type(env, t, "Invalid component_idx");
|
||||
return -EINVAL;
|
||||
@ -3863,7 +3863,7 @@ static s32 btf_tag_check_meta(struct btf_verifier_env *env,
|
||||
return meta_needed;
|
||||
}
|
||||
|
||||
static int btf_tag_resolve(struct btf_verifier_env *env,
|
||||
static int btf_decl_tag_resolve(struct btf_verifier_env *env,
|
||||
const struct resolve_vertex *v)
|
||||
{
|
||||
const struct btf_type *next_type;
|
||||
@ -3874,7 +3874,7 @@ static int btf_tag_resolve(struct btf_verifier_env *env,
|
||||
u32 vlen;
|
||||
|
||||
next_type = btf_type_by_id(btf, next_type_id);
|
||||
if (!next_type || !btf_type_is_tag_target(next_type)) {
|
||||
if (!next_type || !btf_type_is_decl_tag_target(next_type)) {
|
||||
btf_verifier_log_type(env, v->t, "Invalid type_id");
|
||||
return -EINVAL;
|
||||
}
|
||||
@ -3883,7 +3883,7 @@ static int btf_tag_resolve(struct btf_verifier_env *env,
|
||||
!env_type_is_resolved(env, next_type_id))
|
||||
return env_stack_push(env, next_type, next_type_id);
|
||||
|
||||
component_idx = btf_type_tag(t)->component_idx;
|
||||
component_idx = btf_type_decl_tag(t)->component_idx;
|
||||
if (component_idx != -1) {
|
||||
if (btf_type_is_var(next_type)) {
|
||||
btf_verifier_log_type(env, v->t, "Invalid component_idx");
|
||||
@ -3909,18 +3909,18 @@ static int btf_tag_resolve(struct btf_verifier_env *env,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void btf_tag_log(struct btf_verifier_env *env, const struct btf_type *t)
|
||||
static void btf_decl_tag_log(struct btf_verifier_env *env, const struct btf_type *t)
|
||||
{
|
||||
btf_verifier_log(env, "type=%u component_idx=%d", t->type,
|
||||
btf_type_tag(t)->component_idx);
|
||||
btf_type_decl_tag(t)->component_idx);
|
||||
}
|
||||
|
||||
static const struct btf_kind_operations tag_ops = {
|
||||
.check_meta = btf_tag_check_meta,
|
||||
.resolve = btf_tag_resolve,
|
||||
static const struct btf_kind_operations decl_tag_ops = {
|
||||
.check_meta = btf_decl_tag_check_meta,
|
||||
.resolve = btf_decl_tag_resolve,
|
||||
.check_member = btf_df_check_member,
|
||||
.check_kflag_member = btf_df_check_kflag_member,
|
||||
.log_details = btf_tag_log,
|
||||
.log_details = btf_decl_tag_log,
|
||||
.show = btf_df_show,
|
||||
};
|
||||
|
||||
@ -4058,7 +4058,7 @@ static const struct btf_kind_operations * const kind_ops[NR_BTF_KINDS] = {
|
||||
[BTF_KIND_VAR] = &var_ops,
|
||||
[BTF_KIND_DATASEC] = &datasec_ops,
|
||||
[BTF_KIND_FLOAT] = &float_ops,
|
||||
[BTF_KIND_TAG] = &tag_ops,
|
||||
[BTF_KIND_DECL_TAG] = &decl_tag_ops,
|
||||
};
|
||||
|
||||
static s32 btf_check_meta(struct btf_verifier_env *env,
|
||||
@ -4143,7 +4143,7 @@ static bool btf_resolve_valid(struct btf_verifier_env *env,
|
||||
return !btf_resolved_type_id(btf, type_id) &&
|
||||
!btf_resolved_type_size(btf, type_id);
|
||||
|
||||
if (btf_type_is_tag(t))
|
||||
if (btf_type_is_decl_tag(t))
|
||||
return btf_resolved_type_id(btf, type_id) &&
|
||||
!btf_resolved_type_size(btf, type_id);
|
||||
|
||||
|
@ -37,7 +37,7 @@ static const char * const btf_kind_str[NR_BTF_KINDS] = {
|
||||
[BTF_KIND_VAR] = "VAR",
|
||||
[BTF_KIND_DATASEC] = "DATASEC",
|
||||
[BTF_KIND_FLOAT] = "FLOAT",
|
||||
[BTF_KIND_TAG] = "TAG",
|
||||
[BTF_KIND_DECL_TAG] = "DECL_TAG",
|
||||
};
|
||||
|
||||
struct btf_attach_table {
|
||||
@ -348,8 +348,8 @@ static int dump_btf_type(const struct btf *btf, __u32 id,
|
||||
printf(" size=%u", t->size);
|
||||
break;
|
||||
}
|
||||
case BTF_KIND_TAG: {
|
||||
const struct btf_tag *tag = (const void *)(t + 1);
|
||||
case BTF_KIND_DECL_TAG: {
|
||||
const struct btf_decl_tag *tag = (const void *)(t + 1);
|
||||
|
||||
if (json_output) {
|
||||
jsonw_uint_field(w, "type_id", t->type);
|
||||
|
@ -43,7 +43,7 @@ struct btf_type {
|
||||
* "size" tells the size of the type it is describing.
|
||||
*
|
||||
* "type" is used by PTR, TYPEDEF, VOLATILE, CONST, RESTRICT,
|
||||
* FUNC, FUNC_PROTO, VAR and TAG.
|
||||
* FUNC, FUNC_PROTO, VAR and DECL_TAG.
|
||||
* "type" is a type_id referring to another type.
|
||||
*/
|
||||
union {
|
||||
@ -74,7 +74,7 @@ enum {
|
||||
BTF_KIND_VAR = 14, /* Variable */
|
||||
BTF_KIND_DATASEC = 15, /* Section */
|
||||
BTF_KIND_FLOAT = 16, /* Floating point */
|
||||
BTF_KIND_TAG = 17, /* Tag */
|
||||
BTF_KIND_DECL_TAG = 17, /* Decl Tag */
|
||||
|
||||
NR_BTF_KINDS,
|
||||
BTF_KIND_MAX = NR_BTF_KINDS - 1,
|
||||
@ -174,14 +174,14 @@ struct btf_var_secinfo {
|
||||
__u32 size;
|
||||
};
|
||||
|
||||
/* BTF_KIND_TAG is followed by a single "struct btf_tag" to describe
|
||||
/* BTF_KIND_DECL_TAG is followed by a single "struct btf_decl_tag" to describe
|
||||
* additional information related to the tag applied location.
|
||||
* If component_idx == -1, the tag is applied to a struct, union,
|
||||
* variable or function. Otherwise, it is applied to a struct/union
|
||||
* member or a func argument, and component_idx indicates which member
|
||||
* or argument (0 ... vlen-1).
|
||||
*/
|
||||
struct btf_tag {
|
||||
struct btf_decl_tag {
|
||||
__s32 component_idx;
|
||||
};
|
||||
|
||||
|
@ -309,8 +309,8 @@ static int btf_type_size(const struct btf_type *t)
|
||||
return base_size + sizeof(struct btf_var);
|
||||
case BTF_KIND_DATASEC:
|
||||
return base_size + vlen * sizeof(struct btf_var_secinfo);
|
||||
case BTF_KIND_TAG:
|
||||
return base_size + sizeof(struct btf_tag);
|
||||
case BTF_KIND_DECL_TAG:
|
||||
return base_size + sizeof(struct btf_decl_tag);
|
||||
default:
|
||||
pr_debug("Unsupported BTF_KIND:%u\n", btf_kind(t));
|
||||
return -EINVAL;
|
||||
@ -383,8 +383,8 @@ static int btf_bswap_type_rest(struct btf_type *t)
|
||||
v->size = bswap_32(v->size);
|
||||
}
|
||||
return 0;
|
||||
case BTF_KIND_TAG:
|
||||
btf_tag(t)->component_idx = bswap_32(btf_tag(t)->component_idx);
|
||||
case BTF_KIND_DECL_TAG:
|
||||
btf_decl_tag(t)->component_idx = bswap_32(btf_decl_tag(t)->component_idx);
|
||||
return 0;
|
||||
default:
|
||||
pr_debug("Unsupported BTF_KIND:%u\n", btf_kind(t));
|
||||
@ -596,7 +596,7 @@ __s64 btf__resolve_size(const struct btf *btf, __u32 type_id)
|
||||
case BTF_KIND_CONST:
|
||||
case BTF_KIND_RESTRICT:
|
||||
case BTF_KIND_VAR:
|
||||
case BTF_KIND_TAG:
|
||||
case BTF_KIND_DECL_TAG:
|
||||
type_id = t->type;
|
||||
break;
|
||||
case BTF_KIND_ARRAY:
|
||||
@ -2569,7 +2569,7 @@ int btf__add_datasec_var_info(struct btf *btf, int var_type_id, __u32 offset, __
|
||||
}
|
||||
|
||||
/*
|
||||
* Append new BTF_KIND_TAG type with:
|
||||
* Append new BTF_KIND_DECL_TAG type with:
|
||||
* - *value* - non-empty/non-NULL string;
|
||||
* - *ref_type_id* - referenced type ID, it might not exist yet;
|
||||
* - *component_idx* - -1 for tagging reference type, otherwise struct/union
|
||||
@ -2578,7 +2578,7 @@ int btf__add_datasec_var_info(struct btf *btf, int var_type_id, __u32 offset, __
|
||||
* - >0, type ID of newly added BTF type;
|
||||
* - <0, on error.
|
||||
*/
|
||||
int btf__add_tag(struct btf *btf, const char *value, int ref_type_id,
|
||||
int btf__add_decl_tag(struct btf *btf, const char *value, int ref_type_id,
|
||||
int component_idx)
|
||||
{
|
||||
struct btf_type *t;
|
||||
@ -2593,7 +2593,7 @@ int btf__add_tag(struct btf *btf, const char *value, int ref_type_id,
|
||||
if (btf_ensure_modifiable(btf))
|
||||
return libbpf_err(-ENOMEM);
|
||||
|
||||
sz = sizeof(struct btf_type) + sizeof(struct btf_tag);
|
||||
sz = sizeof(struct btf_type) + sizeof(struct btf_decl_tag);
|
||||
t = btf_add_type_mem(btf, sz);
|
||||
if (!t)
|
||||
return libbpf_err(-ENOMEM);
|
||||
@ -2603,9 +2603,9 @@ int btf__add_tag(struct btf *btf, const char *value, int ref_type_id,
|
||||
return value_off;
|
||||
|
||||
t->name_off = value_off;
|
||||
t->info = btf_type_info(BTF_KIND_TAG, 0, false);
|
||||
t->info = btf_type_info(BTF_KIND_DECL_TAG, 0, false);
|
||||
t->type = ref_type_id;
|
||||
btf_tag(t)->component_idx = component_idx;
|
||||
btf_decl_tag(t)->component_idx = component_idx;
|
||||
|
||||
return btf_commit_type(btf, sz);
|
||||
}
|
||||
@ -3427,7 +3427,7 @@ static bool btf_equal_common(struct btf_type *t1, struct btf_type *t2)
|
||||
}
|
||||
|
||||
/* Calculate type signature hash of INT or TAG. */
|
||||
static long btf_hash_int_tag(struct btf_type *t)
|
||||
static long btf_hash_int_decl_tag(struct btf_type *t)
|
||||
{
|
||||
__u32 info = *(__u32 *)(t + 1);
|
||||
long h;
|
||||
@ -3705,8 +3705,8 @@ static int btf_dedup_prep(struct btf_dedup *d)
|
||||
h = btf_hash_common(t);
|
||||
break;
|
||||
case BTF_KIND_INT:
|
||||
case BTF_KIND_TAG:
|
||||
h = btf_hash_int_tag(t);
|
||||
case BTF_KIND_DECL_TAG:
|
||||
h = btf_hash_int_decl_tag(t);
|
||||
break;
|
||||
case BTF_KIND_ENUM:
|
||||
h = btf_hash_enum(t);
|
||||
@ -3761,11 +3761,11 @@ static int btf_dedup_prim_type(struct btf_dedup *d, __u32 type_id)
|
||||
case BTF_KIND_FUNC_PROTO:
|
||||
case BTF_KIND_VAR:
|
||||
case BTF_KIND_DATASEC:
|
||||
case BTF_KIND_TAG:
|
||||
case BTF_KIND_DECL_TAG:
|
||||
return 0;
|
||||
|
||||
case BTF_KIND_INT:
|
||||
h = btf_hash_int_tag(t);
|
||||
h = btf_hash_int_decl_tag(t);
|
||||
for_each_dedup_cand(d, hash_entry, h) {
|
||||
cand_id = (__u32)(long)hash_entry->value;
|
||||
cand = btf_type_by_id(d->btf, cand_id);
|
||||
@ -4382,13 +4382,13 @@ static int btf_dedup_ref_type(struct btf_dedup *d, __u32 type_id)
|
||||
}
|
||||
break;
|
||||
|
||||
case BTF_KIND_TAG:
|
||||
case BTF_KIND_DECL_TAG:
|
||||
ref_type_id = btf_dedup_ref_type(d, t->type);
|
||||
if (ref_type_id < 0)
|
||||
return ref_type_id;
|
||||
t->type = ref_type_id;
|
||||
|
||||
h = btf_hash_int_tag(t);
|
||||
h = btf_hash_int_decl_tag(t);
|
||||
for_each_dedup_cand(d, hash_entry, h) {
|
||||
cand_id = (__u32)(long)hash_entry->value;
|
||||
cand = btf_type_by_id(d->btf, cand_id);
|
||||
@ -4671,7 +4671,7 @@ int btf_type_visit_type_ids(struct btf_type *t, type_id_visit_fn visit, void *ct
|
||||
case BTF_KIND_TYPEDEF:
|
||||
case BTF_KIND_FUNC:
|
||||
case BTF_KIND_VAR:
|
||||
case BTF_KIND_TAG:
|
||||
case BTF_KIND_DECL_TAG:
|
||||
return visit(&t->type, ctx);
|
||||
|
||||
case BTF_KIND_ARRAY: {
|
||||
|
@ -236,7 +236,7 @@ LIBBPF_API int btf__add_datasec_var_info(struct btf *btf, int var_type_id,
|
||||
__u32 offset, __u32 byte_sz);
|
||||
|
||||
/* tag construction API */
|
||||
LIBBPF_API int btf__add_tag(struct btf *btf, const char *value, int ref_type_id,
|
||||
LIBBPF_API int btf__add_decl_tag(struct btf *btf, const char *value, int ref_type_id,
|
||||
int component_idx);
|
||||
|
||||
struct btf_dedup_opts {
|
||||
@ -426,9 +426,9 @@ static inline bool btf_is_float(const struct btf_type *t)
|
||||
return btf_kind(t) == BTF_KIND_FLOAT;
|
||||
}
|
||||
|
||||
static inline bool btf_is_tag(const struct btf_type *t)
|
||||
static inline bool btf_is_decl_tag(const struct btf_type *t)
|
||||
{
|
||||
return btf_kind(t) == BTF_KIND_TAG;
|
||||
return btf_kind(t) == BTF_KIND_DECL_TAG;
|
||||
}
|
||||
|
||||
static inline __u8 btf_int_encoding(const struct btf_type *t)
|
||||
@ -499,10 +499,10 @@ btf_var_secinfos(const struct btf_type *t)
|
||||
return (struct btf_var_secinfo *)(t + 1);
|
||||
}
|
||||
|
||||
struct btf_tag;
|
||||
static inline struct btf_tag *btf_tag(const struct btf_type *t)
|
||||
struct btf_decl_tag;
|
||||
static inline struct btf_decl_tag *btf_decl_tag(const struct btf_type *t)
|
||||
{
|
||||
return (struct btf_tag *)(t + 1);
|
||||
return (struct btf_decl_tag *)(t + 1);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -316,7 +316,7 @@ static int btf_dump_mark_referenced(struct btf_dump *d)
|
||||
case BTF_KIND_TYPEDEF:
|
||||
case BTF_KIND_FUNC:
|
||||
case BTF_KIND_VAR:
|
||||
case BTF_KIND_TAG:
|
||||
case BTF_KIND_DECL_TAG:
|
||||
d->type_states[t->type].referenced = 1;
|
||||
break;
|
||||
|
||||
@ -584,7 +584,7 @@ static int btf_dump_order_type(struct btf_dump *d, __u32 id, bool through_ptr)
|
||||
case BTF_KIND_FUNC:
|
||||
case BTF_KIND_VAR:
|
||||
case BTF_KIND_DATASEC:
|
||||
case BTF_KIND_TAG:
|
||||
case BTF_KIND_DECL_TAG:
|
||||
d->type_states[id].order_state = ORDERED;
|
||||
return 0;
|
||||
|
||||
@ -2217,7 +2217,7 @@ static int btf_dump_dump_type_data(struct btf_dump *d,
|
||||
case BTF_KIND_FWD:
|
||||
case BTF_KIND_FUNC:
|
||||
case BTF_KIND_FUNC_PROTO:
|
||||
case BTF_KIND_TAG:
|
||||
case BTF_KIND_DECL_TAG:
|
||||
err = btf_dump_unsupported_data(d, t, id);
|
||||
break;
|
||||
case BTF_KIND_INT:
|
||||
|
@ -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,
|
||||
},
|
||||
};
|
||||
|
||||
|
@ -394,5 +394,5 @@ LIBBPF_0.6.0 {
|
||||
bpf_object__prev_map;
|
||||
bpf_object__prev_program;
|
||||
btf__add_btf;
|
||||
btf__add_tag;
|
||||
btf__add_decl_tag;
|
||||
} LIBBPF_0.5.0;
|
||||
|
@ -69,8 +69,8 @@
|
||||
#define BTF_VAR_SECINFO_ENC(type, offset, size) (type), (offset), (size)
|
||||
#define BTF_TYPE_FLOAT_ENC(name, sz) \
|
||||
BTF_TYPE_ENC(name, BTF_INFO_ENC(BTF_KIND_FLOAT, 0, 0), sz)
|
||||
#define BTF_TYPE_TAG_ENC(value, type, component_idx) \
|
||||
BTF_TYPE_ENC(value, BTF_INFO_ENC(BTF_KIND_TAG, 0, 0), type), (component_idx)
|
||||
#define BTF_TYPE_DECL_TAG_ENC(value, type, component_idx) \
|
||||
BTF_TYPE_ENC(value, BTF_INFO_ENC(BTF_KIND_DECL_TAG, 0, 0), type), (component_idx)
|
||||
|
||||
#ifndef likely
|
||||
#define likely(x) __builtin_expect(!!(x), 1)
|
||||
|
@ -204,7 +204,7 @@ __ https://reviews.llvm.org/D93563
|
||||
btf_tag test and Clang version
|
||||
==============================
|
||||
|
||||
The btf_tag selftest require LLVM support to recognize the btf_tag attribute.
|
||||
The btf_tag selftest require LLVM support to recognize the btf_decl_tag attribute.
|
||||
It was introduced in `Clang 14`__.
|
||||
|
||||
Without it, the btf_tag selftest will be skipped and you will observe:
|
||||
@ -213,7 +213,7 @@ Without it, the btf_tag selftest will be skipped and you will observe:
|
||||
|
||||
#<test_num> btf_tag:SKIP
|
||||
|
||||
__ https://reviews.llvm.org/D106614
|
||||
__ https://reviews.llvm.org/D111588
|
||||
|
||||
Clang dependencies for static linking tests
|
||||
===========================================
|
||||
|
@ -24,12 +24,12 @@ static const char * const btf_kind_str_mapping[] = {
|
||||
[BTF_KIND_VAR] = "VAR",
|
||||
[BTF_KIND_DATASEC] = "DATASEC",
|
||||
[BTF_KIND_FLOAT] = "FLOAT",
|
||||
[BTF_KIND_TAG] = "TAG",
|
||||
[BTF_KIND_DECL_TAG] = "DECL_TAG",
|
||||
};
|
||||
|
||||
static const char *btf_kind_str(__u16 kind)
|
||||
{
|
||||
if (kind > BTF_KIND_TAG)
|
||||
if (kind > BTF_KIND_DECL_TAG)
|
||||
return "UNKNOWN";
|
||||
return btf_kind_str_mapping[kind];
|
||||
}
|
||||
@ -178,9 +178,9 @@ int fprintf_btf_type_raw(FILE *out, const struct btf *btf, __u32 id)
|
||||
case BTF_KIND_FLOAT:
|
||||
fprintf(out, " size=%u", t->size);
|
||||
break;
|
||||
case BTF_KIND_TAG:
|
||||
case BTF_KIND_DECL_TAG:
|
||||
fprintf(out, " type_id=%u component_idx=%d",
|
||||
t->type, btf_tag(t)->component_idx);
|
||||
t->type, btf_decl_tag(t)->component_idx);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
@ -3662,15 +3662,15 @@ static struct btf_raw_test raw_tests[] = {
|
||||
},
|
||||
|
||||
{
|
||||
.descr = "tag test #1, struct/member, well-formed",
|
||||
.descr = "decl_tag test #1, struct/member, well-formed",
|
||||
.raw_types = {
|
||||
BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
|
||||
BTF_STRUCT_ENC(0, 2, 8), /* [2] */
|
||||
BTF_MEMBER_ENC(NAME_TBD, 1, 0),
|
||||
BTF_MEMBER_ENC(NAME_TBD, 1, 32),
|
||||
BTF_TAG_ENC(NAME_TBD, 2, -1),
|
||||
BTF_TAG_ENC(NAME_TBD, 2, 0),
|
||||
BTF_TAG_ENC(NAME_TBD, 2, 1),
|
||||
BTF_DECL_TAG_ENC(NAME_TBD, 2, -1),
|
||||
BTF_DECL_TAG_ENC(NAME_TBD, 2, 0),
|
||||
BTF_DECL_TAG_ENC(NAME_TBD, 2, 1),
|
||||
BTF_END_RAW,
|
||||
},
|
||||
BTF_STR_SEC("\0m1\0m2\0tag1\0tag2\0tag3"),
|
||||
@ -3683,15 +3683,15 @@ static struct btf_raw_test raw_tests[] = {
|
||||
.max_entries = 1,
|
||||
},
|
||||
{
|
||||
.descr = "tag test #2, union/member, well-formed",
|
||||
.descr = "decl_tag test #2, union/member, well-formed",
|
||||
.raw_types = {
|
||||
BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
|
||||
BTF_UNION_ENC(NAME_TBD, 2, 4), /* [2] */
|
||||
BTF_MEMBER_ENC(NAME_TBD, 1, 0),
|
||||
BTF_MEMBER_ENC(NAME_TBD, 1, 0),
|
||||
BTF_TAG_ENC(NAME_TBD, 2, -1),
|
||||
BTF_TAG_ENC(NAME_TBD, 2, 0),
|
||||
BTF_TAG_ENC(NAME_TBD, 2, 1),
|
||||
BTF_DECL_TAG_ENC(NAME_TBD, 2, -1),
|
||||
BTF_DECL_TAG_ENC(NAME_TBD, 2, 0),
|
||||
BTF_DECL_TAG_ENC(NAME_TBD, 2, 1),
|
||||
BTF_END_RAW,
|
||||
},
|
||||
BTF_STR_SEC("\0t\0m1\0m2\0tag1\0tag2\0tag3"),
|
||||
@ -3704,13 +3704,13 @@ static struct btf_raw_test raw_tests[] = {
|
||||
.max_entries = 1,
|
||||
},
|
||||
{
|
||||
.descr = "tag test #3, variable, well-formed",
|
||||
.descr = "decl_tag test #3, variable, well-formed",
|
||||
.raw_types = {
|
||||
BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
|
||||
BTF_VAR_ENC(NAME_TBD, 1, 0), /* [2] */
|
||||
BTF_VAR_ENC(NAME_TBD, 1, 1), /* [3] */
|
||||
BTF_TAG_ENC(NAME_TBD, 2, -1),
|
||||
BTF_TAG_ENC(NAME_TBD, 3, -1),
|
||||
BTF_DECL_TAG_ENC(NAME_TBD, 2, -1),
|
||||
BTF_DECL_TAG_ENC(NAME_TBD, 3, -1),
|
||||
BTF_END_RAW,
|
||||
},
|
||||
BTF_STR_SEC("\0local\0global\0tag1\0tag2"),
|
||||
@ -3723,16 +3723,16 @@ static struct btf_raw_test raw_tests[] = {
|
||||
.max_entries = 1,
|
||||
},
|
||||
{
|
||||
.descr = "tag test #4, func/parameter, well-formed",
|
||||
.descr = "decl_tag test #4, func/parameter, well-formed",
|
||||
.raw_types = {
|
||||
BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
|
||||
BTF_FUNC_PROTO_ENC(0, 2), /* [2] */
|
||||
BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
|
||||
BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
|
||||
BTF_FUNC_ENC(NAME_TBD, 2), /* [3] */
|
||||
BTF_TAG_ENC(NAME_TBD, 3, -1),
|
||||
BTF_TAG_ENC(NAME_TBD, 3, 0),
|
||||
BTF_TAG_ENC(NAME_TBD, 3, 1),
|
||||
BTF_DECL_TAG_ENC(NAME_TBD, 3, -1),
|
||||
BTF_DECL_TAG_ENC(NAME_TBD, 3, 0),
|
||||
BTF_DECL_TAG_ENC(NAME_TBD, 3, 1),
|
||||
BTF_END_RAW,
|
||||
},
|
||||
BTF_STR_SEC("\0arg1\0arg2\0f\0tag1\0tag2\0tag3"),
|
||||
@ -3745,11 +3745,11 @@ static struct btf_raw_test raw_tests[] = {
|
||||
.max_entries = 1,
|
||||
},
|
||||
{
|
||||
.descr = "tag test #5, invalid value",
|
||||
.descr = "decl_tag test #5, invalid value",
|
||||
.raw_types = {
|
||||
BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
|
||||
BTF_VAR_ENC(NAME_TBD, 1, 0), /* [2] */
|
||||
BTF_TAG_ENC(0, 2, -1),
|
||||
BTF_DECL_TAG_ENC(0, 2, -1),
|
||||
BTF_END_RAW,
|
||||
},
|
||||
BTF_STR_SEC("\0local\0tag"),
|
||||
@ -3764,10 +3764,10 @@ static struct btf_raw_test raw_tests[] = {
|
||||
.err_str = "Invalid value",
|
||||
},
|
||||
{
|
||||
.descr = "tag test #6, invalid target type",
|
||||
.descr = "decl_tag test #6, invalid target type",
|
||||
.raw_types = {
|
||||
BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
|
||||
BTF_TAG_ENC(NAME_TBD, 1, -1),
|
||||
BTF_DECL_TAG_ENC(NAME_TBD, 1, -1),
|
||||
BTF_END_RAW,
|
||||
},
|
||||
BTF_STR_SEC("\0tag1"),
|
||||
@ -3782,11 +3782,11 @@ static struct btf_raw_test raw_tests[] = {
|
||||
.err_str = "Invalid type",
|
||||
},
|
||||
{
|
||||
.descr = "tag test #7, invalid vlen",
|
||||
.descr = "decl_tag test #7, invalid vlen",
|
||||
.raw_types = {
|
||||
BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
|
||||
BTF_VAR_ENC(NAME_TBD, 1, 0), /* [2] */
|
||||
BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_TAG, 0, 1), 2), (0),
|
||||
BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_DECL_TAG, 0, 1), 2), (0),
|
||||
BTF_END_RAW,
|
||||
},
|
||||
BTF_STR_SEC("\0local\0tag1"),
|
||||
@ -3801,11 +3801,11 @@ static struct btf_raw_test raw_tests[] = {
|
||||
.err_str = "vlen != 0",
|
||||
},
|
||||
{
|
||||
.descr = "tag test #8, invalid kflag",
|
||||
.descr = "decl_tag test #8, invalid kflag",
|
||||
.raw_types = {
|
||||
BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
|
||||
BTF_VAR_ENC(NAME_TBD, 1, 0), /* [2] */
|
||||
BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_TAG, 1, 0), 2), (-1),
|
||||
BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_DECL_TAG, 1, 0), 2), (-1),
|
||||
BTF_END_RAW,
|
||||
},
|
||||
BTF_STR_SEC("\0local\0tag1"),
|
||||
@ -3820,11 +3820,11 @@ static struct btf_raw_test raw_tests[] = {
|
||||
.err_str = "Invalid btf_info kind_flag",
|
||||
},
|
||||
{
|
||||
.descr = "tag test #9, var, invalid component_idx",
|
||||
.descr = "decl_tag test #9, var, invalid component_idx",
|
||||
.raw_types = {
|
||||
BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
|
||||
BTF_VAR_ENC(NAME_TBD, 1, 0), /* [2] */
|
||||
BTF_TAG_ENC(NAME_TBD, 2, 0),
|
||||
BTF_DECL_TAG_ENC(NAME_TBD, 2, 0),
|
||||
BTF_END_RAW,
|
||||
},
|
||||
BTF_STR_SEC("\0local\0tag"),
|
||||
@ -3839,13 +3839,13 @@ static struct btf_raw_test raw_tests[] = {
|
||||
.err_str = "Invalid component_idx",
|
||||
},
|
||||
{
|
||||
.descr = "tag test #10, struct member, invalid component_idx",
|
||||
.descr = "decl_tag test #10, struct member, invalid component_idx",
|
||||
.raw_types = {
|
||||
BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
|
||||
BTF_STRUCT_ENC(0, 2, 8), /* [2] */
|
||||
BTF_MEMBER_ENC(NAME_TBD, 1, 0),
|
||||
BTF_MEMBER_ENC(NAME_TBD, 1, 32),
|
||||
BTF_TAG_ENC(NAME_TBD, 2, 2),
|
||||
BTF_DECL_TAG_ENC(NAME_TBD, 2, 2),
|
||||
BTF_END_RAW,
|
||||
},
|
||||
BTF_STR_SEC("\0m1\0m2\0tag"),
|
||||
@ -3860,14 +3860,14 @@ static struct btf_raw_test raw_tests[] = {
|
||||
.err_str = "Invalid component_idx",
|
||||
},
|
||||
{
|
||||
.descr = "tag test #11, func parameter, invalid component_idx",
|
||||
.descr = "decl_tag test #11, func parameter, invalid component_idx",
|
||||
.raw_types = {
|
||||
BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
|
||||
BTF_FUNC_PROTO_ENC(0, 2), /* [2] */
|
||||
BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
|
||||
BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
|
||||
BTF_FUNC_ENC(NAME_TBD, 2), /* [3] */
|
||||
BTF_TAG_ENC(NAME_TBD, 3, 2),
|
||||
BTF_DECL_TAG_ENC(NAME_TBD, 3, 2),
|
||||
BTF_END_RAW,
|
||||
},
|
||||
BTF_STR_SEC("\0arg1\0arg2\0f\0tag"),
|
||||
@ -3882,14 +3882,14 @@ static struct btf_raw_test raw_tests[] = {
|
||||
.err_str = "Invalid component_idx",
|
||||
},
|
||||
{
|
||||
.descr = "tag test #12, < -1 component_idx",
|
||||
.descr = "decl_tag test #12, < -1 component_idx",
|
||||
.raw_types = {
|
||||
BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
|
||||
BTF_FUNC_PROTO_ENC(0, 2), /* [2] */
|
||||
BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
|
||||
BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
|
||||
BTF_FUNC_ENC(NAME_TBD, 2), /* [3] */
|
||||
BTF_TAG_ENC(NAME_TBD, 3, -2),
|
||||
BTF_DECL_TAG_ENC(NAME_TBD, 3, -2),
|
||||
BTF_END_RAW,
|
||||
},
|
||||
BTF_STR_SEC("\0arg1\0arg2\0f\0tag"),
|
||||
@ -6672,9 +6672,9 @@ const struct btf_dedup_test dedup_tests[] = {
|
||||
/* const -> [1] int */
|
||||
BTF_CONST_ENC(1), /* [6] */
|
||||
/* tag -> [3] struct s */
|
||||
BTF_TAG_ENC(NAME_NTH(2), 3, -1), /* [7] */
|
||||
BTF_DECL_TAG_ENC(NAME_NTH(2), 3, -1), /* [7] */
|
||||
/* tag -> [3] struct s, member 1 */
|
||||
BTF_TAG_ENC(NAME_NTH(2), 3, 1), /* [8] */
|
||||
BTF_DECL_TAG_ENC(NAME_NTH(2), 3, 1), /* [8] */
|
||||
|
||||
/* full copy of the above */
|
||||
BTF_TYPE_INT_ENC(NAME_NTH(1), BTF_INT_SIGNED, 0, 32, 4), /* [9] */
|
||||
@ -6689,8 +6689,8 @@ const struct btf_dedup_test dedup_tests[] = {
|
||||
BTF_PTR_ENC(14), /* [13] */
|
||||
BTF_CONST_ENC(9), /* [14] */
|
||||
BTF_TYPE_FLOAT_ENC(NAME_NTH(7), 4), /* [15] */
|
||||
BTF_TAG_ENC(NAME_NTH(2), 11, -1), /* [16] */
|
||||
BTF_TAG_ENC(NAME_NTH(2), 11, 1), /* [17] */
|
||||
BTF_DECL_TAG_ENC(NAME_NTH(2), 11, -1), /* [16] */
|
||||
BTF_DECL_TAG_ENC(NAME_NTH(2), 11, 1), /* [17] */
|
||||
BTF_END_RAW,
|
||||
},
|
||||
BTF_STR_SEC("\0int\0s\0next\0a\0b\0c\0float\0d"),
|
||||
@ -6714,8 +6714,8 @@ const struct btf_dedup_test dedup_tests[] = {
|
||||
BTF_PTR_ENC(6), /* [5] */
|
||||
/* const -> [1] int */
|
||||
BTF_CONST_ENC(1), /* [6] */
|
||||
BTF_TAG_ENC(NAME_NTH(2), 3, -1), /* [7] */
|
||||
BTF_TAG_ENC(NAME_NTH(2), 3, 1), /* [8] */
|
||||
BTF_DECL_TAG_ENC(NAME_NTH(2), 3, -1), /* [7] */
|
||||
BTF_DECL_TAG_ENC(NAME_NTH(2), 3, 1), /* [8] */
|
||||
BTF_TYPE_FLOAT_ENC(NAME_NTH(7), 4), /* [9] */
|
||||
BTF_END_RAW,
|
||||
},
|
||||
@ -6841,8 +6841,8 @@ const struct btf_dedup_test dedup_tests[] = {
|
||||
BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 8),
|
||||
BTF_FUNC_ENC(NAME_TBD, 12), /* [13] func */
|
||||
BTF_TYPE_FLOAT_ENC(NAME_TBD, 2), /* [14] float */
|
||||
BTF_TAG_ENC(NAME_TBD, 13, -1), /* [15] tag */
|
||||
BTF_TAG_ENC(NAME_TBD, 13, 1), /* [16] tag */
|
||||
BTF_DECL_TAG_ENC(NAME_TBD, 13, -1), /* [15] tag */
|
||||
BTF_DECL_TAG_ENC(NAME_TBD, 13, 1), /* [16] tag */
|
||||
BTF_END_RAW,
|
||||
},
|
||||
BTF_STR_SEC("\0A\0B\0C\0D\0E\0F\0G\0H\0I\0J\0K\0L\0M\0N\0O\0P"),
|
||||
@ -6869,8 +6869,8 @@ const struct btf_dedup_test dedup_tests[] = {
|
||||
BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 8),
|
||||
BTF_FUNC_ENC(NAME_TBD, 12), /* [13] func */
|
||||
BTF_TYPE_FLOAT_ENC(NAME_TBD, 2), /* [14] float */
|
||||
BTF_TAG_ENC(NAME_TBD, 13, -1), /* [15] tag */
|
||||
BTF_TAG_ENC(NAME_TBD, 13, 1), /* [16] tag */
|
||||
BTF_DECL_TAG_ENC(NAME_TBD, 13, -1), /* [15] tag */
|
||||
BTF_DECL_TAG_ENC(NAME_TBD, 13, 1), /* [16] tag */
|
||||
BTF_END_RAW,
|
||||
},
|
||||
BTF_STR_SEC("\0A\0B\0C\0D\0E\0F\0G\0H\0I\0J\0K\0L\0M\0N\0O\0P"),
|
||||
@ -7036,14 +7036,14 @@ const struct btf_dedup_test dedup_tests[] = {
|
||||
BTF_FUNC_PROTO_ARG_ENC(NAME_NTH(3), 1),
|
||||
BTF_FUNC_ENC(NAME_NTH(4), 2), /* [4] */
|
||||
/* tag -> t */
|
||||
BTF_TAG_ENC(NAME_NTH(5), 2, -1), /* [5] */
|
||||
BTF_TAG_ENC(NAME_NTH(5), 2, -1), /* [6] */
|
||||
BTF_DECL_TAG_ENC(NAME_NTH(5), 2, -1), /* [5] */
|
||||
BTF_DECL_TAG_ENC(NAME_NTH(5), 2, -1), /* [6] */
|
||||
/* tag -> func */
|
||||
BTF_TAG_ENC(NAME_NTH(5), 4, -1), /* [7] */
|
||||
BTF_TAG_ENC(NAME_NTH(5), 4, -1), /* [8] */
|
||||
BTF_DECL_TAG_ENC(NAME_NTH(5), 4, -1), /* [7] */
|
||||
BTF_DECL_TAG_ENC(NAME_NTH(5), 4, -1), /* [8] */
|
||||
/* tag -> func arg a1 */
|
||||
BTF_TAG_ENC(NAME_NTH(5), 4, 1), /* [9] */
|
||||
BTF_TAG_ENC(NAME_NTH(5), 4, 1), /* [10] */
|
||||
BTF_DECL_TAG_ENC(NAME_NTH(5), 4, 1), /* [9] */
|
||||
BTF_DECL_TAG_ENC(NAME_NTH(5), 4, 1), /* [10] */
|
||||
BTF_END_RAW,
|
||||
},
|
||||
BTF_STR_SEC("\0t\0a1\0a2\0f\0tag"),
|
||||
@ -7056,9 +7056,9 @@ const struct btf_dedup_test dedup_tests[] = {
|
||||
BTF_FUNC_PROTO_ARG_ENC(NAME_NTH(2), 1),
|
||||
BTF_FUNC_PROTO_ARG_ENC(NAME_NTH(3), 1),
|
||||
BTF_FUNC_ENC(NAME_NTH(4), 2), /* [4] */
|
||||
BTF_TAG_ENC(NAME_NTH(5), 2, -1), /* [5] */
|
||||
BTF_TAG_ENC(NAME_NTH(5), 4, -1), /* [6] */
|
||||
BTF_TAG_ENC(NAME_NTH(5), 4, 1), /* [7] */
|
||||
BTF_DECL_TAG_ENC(NAME_NTH(5), 2, -1), /* [5] */
|
||||
BTF_DECL_TAG_ENC(NAME_NTH(5), 4, -1), /* [6] */
|
||||
BTF_DECL_TAG_ENC(NAME_NTH(5), 4, 1), /* [7] */
|
||||
BTF_END_RAW,
|
||||
},
|
||||
BTF_STR_SEC("\0t\0a1\0a2\0f\0tag"),
|
||||
@ -7084,17 +7084,17 @@ const struct btf_dedup_test dedup_tests[] = {
|
||||
BTF_FUNC_PROTO_ARG_ENC(NAME_NTH(2), 1),
|
||||
BTF_FUNC_ENC(NAME_NTH(3), 4), /* [5] */
|
||||
/* tag -> f: tag1, tag2 */
|
||||
BTF_TAG_ENC(NAME_NTH(4), 3, -1), /* [6] */
|
||||
BTF_TAG_ENC(NAME_NTH(5), 3, -1), /* [7] */
|
||||
BTF_DECL_TAG_ENC(NAME_NTH(4), 3, -1), /* [6] */
|
||||
BTF_DECL_TAG_ENC(NAME_NTH(5), 3, -1), /* [7] */
|
||||
/* tag -> f/a2: tag1, tag2 */
|
||||
BTF_TAG_ENC(NAME_NTH(4), 3, 1), /* [8] */
|
||||
BTF_TAG_ENC(NAME_NTH(5), 3, 1), /* [9] */
|
||||
BTF_DECL_TAG_ENC(NAME_NTH(4), 3, 1), /* [8] */
|
||||
BTF_DECL_TAG_ENC(NAME_NTH(5), 3, 1), /* [9] */
|
||||
/* tag -> f: tag1, tag3 */
|
||||
BTF_TAG_ENC(NAME_NTH(4), 5, -1), /* [10] */
|
||||
BTF_TAG_ENC(NAME_NTH(6), 5, -1), /* [11] */
|
||||
BTF_DECL_TAG_ENC(NAME_NTH(4), 5, -1), /* [10] */
|
||||
BTF_DECL_TAG_ENC(NAME_NTH(6), 5, -1), /* [11] */
|
||||
/* tag -> f/a2: tag1, tag3 */
|
||||
BTF_TAG_ENC(NAME_NTH(4), 5, 1), /* [12] */
|
||||
BTF_TAG_ENC(NAME_NTH(6), 5, 1), /* [13] */
|
||||
BTF_DECL_TAG_ENC(NAME_NTH(4), 5, 1), /* [12] */
|
||||
BTF_DECL_TAG_ENC(NAME_NTH(6), 5, 1), /* [13] */
|
||||
BTF_END_RAW,
|
||||
},
|
||||
BTF_STR_SEC("\0a1\0a2\0f\0tag1\0tag2\0tag3"),
|
||||
@ -7106,12 +7106,12 @@ const struct btf_dedup_test dedup_tests[] = {
|
||||
BTF_FUNC_PROTO_ARG_ENC(NAME_NTH(1), 1),
|
||||
BTF_FUNC_PROTO_ARG_ENC(NAME_NTH(2), 1),
|
||||
BTF_FUNC_ENC(NAME_NTH(3), 2), /* [3] */
|
||||
BTF_TAG_ENC(NAME_NTH(4), 3, -1), /* [4] */
|
||||
BTF_TAG_ENC(NAME_NTH(5), 3, -1), /* [5] */
|
||||
BTF_TAG_ENC(NAME_NTH(6), 3, -1), /* [6] */
|
||||
BTF_TAG_ENC(NAME_NTH(4), 3, 1), /* [7] */
|
||||
BTF_TAG_ENC(NAME_NTH(5), 3, 1), /* [8] */
|
||||
BTF_TAG_ENC(NAME_NTH(6), 3, 1), /* [9] */
|
||||
BTF_DECL_TAG_ENC(NAME_NTH(4), 3, -1), /* [4] */
|
||||
BTF_DECL_TAG_ENC(NAME_NTH(5), 3, -1), /* [5] */
|
||||
BTF_DECL_TAG_ENC(NAME_NTH(6), 3, -1), /* [6] */
|
||||
BTF_DECL_TAG_ENC(NAME_NTH(4), 3, 1), /* [7] */
|
||||
BTF_DECL_TAG_ENC(NAME_NTH(5), 3, 1), /* [8] */
|
||||
BTF_DECL_TAG_ENC(NAME_NTH(6), 3, 1), /* [9] */
|
||||
BTF_END_RAW,
|
||||
},
|
||||
BTF_STR_SEC("\0a1\0a2\0f\0tag1\0tag2\0tag3"),
|
||||
@ -7133,17 +7133,17 @@ const struct btf_dedup_test dedup_tests[] = {
|
||||
BTF_MEMBER_ENC(NAME_NTH(2), 1, 0),
|
||||
BTF_MEMBER_ENC(NAME_NTH(3), 1, 32),
|
||||
/* tag -> t: tag1, tag2 */
|
||||
BTF_TAG_ENC(NAME_NTH(4), 2, -1), /* [4] */
|
||||
BTF_TAG_ENC(NAME_NTH(5), 2, -1), /* [5] */
|
||||
BTF_DECL_TAG_ENC(NAME_NTH(4), 2, -1), /* [4] */
|
||||
BTF_DECL_TAG_ENC(NAME_NTH(5), 2, -1), /* [5] */
|
||||
/* tag -> t/m2: tag1, tag2 */
|
||||
BTF_TAG_ENC(NAME_NTH(4), 2, 1), /* [6] */
|
||||
BTF_TAG_ENC(NAME_NTH(5), 2, 1), /* [7] */
|
||||
BTF_DECL_TAG_ENC(NAME_NTH(4), 2, 1), /* [6] */
|
||||
BTF_DECL_TAG_ENC(NAME_NTH(5), 2, 1), /* [7] */
|
||||
/* tag -> t: tag1, tag3 */
|
||||
BTF_TAG_ENC(NAME_NTH(4), 3, -1), /* [8] */
|
||||
BTF_TAG_ENC(NAME_NTH(6), 3, -1), /* [9] */
|
||||
BTF_DECL_TAG_ENC(NAME_NTH(4), 3, -1), /* [8] */
|
||||
BTF_DECL_TAG_ENC(NAME_NTH(6), 3, -1), /* [9] */
|
||||
/* tag -> t/m2: tag1, tag3 */
|
||||
BTF_TAG_ENC(NAME_NTH(4), 3, 1), /* [10] */
|
||||
BTF_TAG_ENC(NAME_NTH(6), 3, 1), /* [11] */
|
||||
BTF_DECL_TAG_ENC(NAME_NTH(4), 3, 1), /* [10] */
|
||||
BTF_DECL_TAG_ENC(NAME_NTH(6), 3, 1), /* [11] */
|
||||
BTF_END_RAW,
|
||||
},
|
||||
BTF_STR_SEC("\0t\0m1\0m2\0tag1\0tag2\0tag3"),
|
||||
@ -7154,12 +7154,12 @@ const struct btf_dedup_test dedup_tests[] = {
|
||||
BTF_STRUCT_ENC(NAME_NTH(1), 2, 8), /* [2] */
|
||||
BTF_MEMBER_ENC(NAME_NTH(2), 1, 0),
|
||||
BTF_MEMBER_ENC(NAME_NTH(3), 1, 32),
|
||||
BTF_TAG_ENC(NAME_NTH(4), 2, -1), /* [3] */
|
||||
BTF_TAG_ENC(NAME_NTH(5), 2, -1), /* [4] */
|
||||
BTF_TAG_ENC(NAME_NTH(6), 2, -1), /* [5] */
|
||||
BTF_TAG_ENC(NAME_NTH(4), 2, 1), /* [6] */
|
||||
BTF_TAG_ENC(NAME_NTH(5), 2, 1), /* [7] */
|
||||
BTF_TAG_ENC(NAME_NTH(6), 2, 1), /* [8] */
|
||||
BTF_DECL_TAG_ENC(NAME_NTH(4), 2, -1), /* [3] */
|
||||
BTF_DECL_TAG_ENC(NAME_NTH(5), 2, -1), /* [4] */
|
||||
BTF_DECL_TAG_ENC(NAME_NTH(6), 2, -1), /* [5] */
|
||||
BTF_DECL_TAG_ENC(NAME_NTH(4), 2, 1), /* [6] */
|
||||
BTF_DECL_TAG_ENC(NAME_NTH(5), 2, 1), /* [7] */
|
||||
BTF_DECL_TAG_ENC(NAME_NTH(6), 2, 1), /* [8] */
|
||||
BTF_END_RAW,
|
||||
},
|
||||
BTF_STR_SEC("\0t\0m1\0m2\0tag1\0tag2\0tag3"),
|
||||
@ -7202,8 +7202,8 @@ static int btf_type_size(const struct btf_type *t)
|
||||
return base_size + sizeof(struct btf_var);
|
||||
case BTF_KIND_DATASEC:
|
||||
return base_size + vlen * sizeof(struct btf_var_secinfo);
|
||||
case BTF_KIND_TAG:
|
||||
return base_size + sizeof(struct btf_tag);
|
||||
case BTF_KIND_DECL_TAG:
|
||||
return base_size + sizeof(struct btf_decl_tag);
|
||||
default:
|
||||
fprintf(stderr, "Unsupported BTF_KIND:%u\n", kind);
|
||||
return -EINVAL;
|
||||
|
@ -277,26 +277,26 @@ static void gen_btf(struct btf *btf)
|
||||
"[17] DATASEC 'datasec1' size=12 vlen=1\n"
|
||||
"\ttype_id=1 offset=4 size=8", "raw_dump");
|
||||
|
||||
/* TAG */
|
||||
id = btf__add_tag(btf, "tag1", 16, -1);
|
||||
/* DECL_TAG */
|
||||
id = btf__add_decl_tag(btf, "tag1", 16, -1);
|
||||
ASSERT_EQ(id, 18, "tag_id");
|
||||
t = btf__type_by_id(btf, 18);
|
||||
ASSERT_STREQ(btf__str_by_offset(btf, t->name_off), "tag1", "tag_value");
|
||||
ASSERT_EQ(btf_kind(t), BTF_KIND_TAG, "tag_kind");
|
||||
ASSERT_EQ(btf_kind(t), BTF_KIND_DECL_TAG, "tag_kind");
|
||||
ASSERT_EQ(t->type, 16, "tag_type");
|
||||
ASSERT_EQ(btf_tag(t)->component_idx, -1, "tag_component_idx");
|
||||
ASSERT_EQ(btf_decl_tag(t)->component_idx, -1, "tag_component_idx");
|
||||
ASSERT_STREQ(btf_type_raw_dump(btf, 18),
|
||||
"[18] TAG 'tag1' type_id=16 component_idx=-1", "raw_dump");
|
||||
"[18] DECL_TAG 'tag1' type_id=16 component_idx=-1", "raw_dump");
|
||||
|
||||
id = btf__add_tag(btf, "tag2", 14, 1);
|
||||
id = btf__add_decl_tag(btf, "tag2", 14, 1);
|
||||
ASSERT_EQ(id, 19, "tag_id");
|
||||
t = btf__type_by_id(btf, 19);
|
||||
ASSERT_STREQ(btf__str_by_offset(btf, t->name_off), "tag2", "tag_value");
|
||||
ASSERT_EQ(btf_kind(t), BTF_KIND_TAG, "tag_kind");
|
||||
ASSERT_EQ(btf_kind(t), BTF_KIND_DECL_TAG, "tag_kind");
|
||||
ASSERT_EQ(t->type, 14, "tag_type");
|
||||
ASSERT_EQ(btf_tag(t)->component_idx, 1, "tag_component_idx");
|
||||
ASSERT_EQ(btf_decl_tag(t)->component_idx, 1, "tag_component_idx");
|
||||
ASSERT_STREQ(btf_type_raw_dump(btf, 19),
|
||||
"[19] TAG 'tag2' type_id=14 component_idx=1", "raw_dump");
|
||||
"[19] DECL_TAG 'tag2' type_id=14 component_idx=1", "raw_dump");
|
||||
}
|
||||
|
||||
static void test_btf_add()
|
||||
@ -336,8 +336,8 @@ static void test_btf_add()
|
||||
"[16] VAR 'var1' type_id=1, linkage=global-alloc",
|
||||
"[17] DATASEC 'datasec1' size=12 vlen=1\n"
|
||||
"\ttype_id=1 offset=4 size=8",
|
||||
"[18] TAG 'tag1' type_id=16 component_idx=-1",
|
||||
"[19] TAG 'tag2' type_id=14 component_idx=1");
|
||||
"[18] DECL_TAG 'tag1' type_id=16 component_idx=-1",
|
||||
"[19] DECL_TAG 'tag2' type_id=14 component_idx=1");
|
||||
|
||||
btf__free(btf);
|
||||
}
|
||||
@ -389,8 +389,8 @@ static void test_btf_add_btf()
|
||||
"[16] VAR 'var1' type_id=1, linkage=global-alloc",
|
||||
"[17] DATASEC 'datasec1' size=12 vlen=1\n"
|
||||
"\ttype_id=1 offset=4 size=8",
|
||||
"[18] TAG 'tag1' type_id=16 component_idx=-1",
|
||||
"[19] TAG 'tag2' type_id=14 component_idx=1",
|
||||
"[18] DECL_TAG 'tag1' type_id=16 component_idx=-1",
|
||||
"[19] DECL_TAG 'tag2' type_id=14 component_idx=1",
|
||||
|
||||
/* types appended from the second BTF */
|
||||
"[20] INT 'int' size=4 bits_offset=0 nr_bits=32 encoding=SIGNED",
|
||||
@ -418,8 +418,8 @@ static void test_btf_add_btf()
|
||||
"[35] VAR 'var1' type_id=20, linkage=global-alloc",
|
||||
"[36] DATASEC 'datasec1' size=12 vlen=1\n"
|
||||
"\ttype_id=20 offset=4 size=8",
|
||||
"[37] TAG 'tag1' type_id=35 component_idx=-1",
|
||||
"[38] TAG 'tag2' type_id=33 component_idx=1");
|
||||
"[37] DECL_TAG 'tag1' type_id=35 component_idx=-1",
|
||||
"[38] DECL_TAG 'tag2' type_id=33 component_idx=1");
|
||||
|
||||
cleanup:
|
||||
btf__free(btf1);
|
||||
|
@ -8,9 +8,9 @@
|
||||
#define __has_attribute(x) 0
|
||||
#endif
|
||||
|
||||
#if __has_attribute(btf_tag)
|
||||
#define __tag1 __attribute__((btf_tag("tag1")))
|
||||
#define __tag2 __attribute__((btf_tag("tag2")))
|
||||
#if __has_attribute(btf_decl_tag)
|
||||
#define __tag1 __attribute__((btf_decl_tag("tag1")))
|
||||
#define __tag2 __attribute__((btf_decl_tag("tag2")))
|
||||
volatile const bool skip_tests __tag1 __tag2 = false;
|
||||
#else
|
||||
#define __tag1
|
||||
|
@ -69,7 +69,7 @@
|
||||
#define BTF_TYPE_FLOAT_ENC(name, sz) \
|
||||
BTF_TYPE_ENC(name, BTF_INFO_ENC(BTF_KIND_FLOAT, 0, 0), sz)
|
||||
|
||||
#define BTF_TAG_ENC(value, type, component_idx) \
|
||||
BTF_TYPE_ENC(value, BTF_INFO_ENC(BTF_KIND_TAG, 0, 0), type), (component_idx)
|
||||
#define BTF_DECL_TAG_ENC(value, type, component_idx) \
|
||||
BTF_TYPE_ENC(value, BTF_INFO_ENC(BTF_KIND_DECL_TAG, 0, 0), type), (component_idx)
|
||||
|
||||
#endif /* _TEST_BTF_H */
|
||||
|
Loading…
Reference in New Issue
Block a user