btf_encoder: generate BTF_KIND_DECL_TAGs for typedef btf_decl_tag attributes
Emit BTF BTF_KIND_DECL_TAGs for btf_decl_tag attributes attached to typedef declarations. The following is a simple example: $ cat t.c #define __tag1 __attribute__((btf_decl_tag("tag1"))) #define __tag2 __attribute__((btf_decl_tag("tag2"))) typedef struct { int a; int b; } __t __tag1 __tag2; __t g; $ clang -O2 -g -c t.c $ pahole -JV t.o btf_encoder__new: 't.o' doesn't have '.data..percpu' section Found 0 per-CPU variables! File t.o: [1] TYPEDEF __t type_id=2 [2] STRUCT (anon) size=8 a type_id=3 bits_offset=0 b type_id=3 bits_offset=32 [3] INT int size=4 nr_bits=32 encoding=SIGNED [4] DECL_TAG tag1 type_id=1 component_idx=-1 [5] DECL_TAG tag2 type_id=1 component_idx=-1 Signed-off-by: Yonghong Song <yhs@fb.com> Cc: Alexei Starovoitov <ast@kernel.org> Cc: Andrii Nakryiko <andrii@kernel.org> Cc: Daniel Borkmann <daniel@iogearbox.net> Cc: bpf@vger.kernel.org Cc: dwarves@vger.kernel.org Cc: kernel-team@fb.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
parent
468b4196f6
commit
ec62499774
|
@ -1438,9 +1438,21 @@ int btf_encoder__encode_cu(struct btf_encoder *encoder, struct cu *cu)
|
|||
|
||||
cu__for_each_type(cu, core_id, pos) {
|
||||
struct namespace *ns;
|
||||
const char *tag_name;
|
||||
|
||||
if (pos->tag != DW_TAG_structure_type && pos->tag != DW_TAG_union_type)
|
||||
switch (pos->tag) {
|
||||
case DW_TAG_structure_type:
|
||||
tag_name = "struct";
|
||||
break;
|
||||
case DW_TAG_union_type:
|
||||
tag_name = "union";
|
||||
break;
|
||||
case DW_TAG_typedef:
|
||||
tag_name = "typedef";
|
||||
break;
|
||||
default:
|
||||
continue;
|
||||
}
|
||||
|
||||
btf_type_id = type_id_off + core_id;
|
||||
ns = tag__namespace(pos);
|
||||
|
@ -1448,8 +1460,7 @@ int btf_encoder__encode_cu(struct btf_encoder *encoder, struct cu *cu)
|
|||
tag_type_id = btf_encoder__add_decl_tag(encoder, annot->value, btf_type_id, annot->component_idx);
|
||||
if (tag_type_id < 0) {
|
||||
fprintf(stderr, "error: failed to encode tag '%s' to %s '%s' with component_idx %d\n",
|
||||
annot->value, pos->tag == DW_TAG_structure_type ? "struct" : "union",
|
||||
namespace__name(ns), annot->component_idx);
|
||||
annot->value, tag_name, namespace__name(ns), annot->component_idx);
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue