On 9/8/21 10:33 PM, Andrii Nakryiko wrote:
On Wed, Sep 8, 2021 at 10:28 PM Andrii Nakryiko
<andrii.nakryiko@xxxxxxxxx> wrote:
On Tue, Sep 7, 2021 at 4:01 PM Yonghong Song <yhs@xxxxxx> wrote:
added bpftool support to dump BTF_KIND_TAG information.
The new bpftool will be used in later patches to dump
btf in the test bpf program object file.
What should be done for `bpftool btf dump file <path> format c` if BTF
contains btf_tag? Should it ignore it silently? Should it error out?
Or should we corrupt output (as will be the case right now, I think)?
Currently it is silently ignored. The attribute information is mostly
used in the kernel by verification purpose and the kernel uses its own
btf to check.
Adding such attributes to vmlinux.h, bpf program BTF will contain these
attributes but they may not be used by the kernel verifier at least
for now.
So I think we can delay this as a followup if there is a real need.
Signed-off-by: Yonghong Song <yhs@xxxxxx>
---
tools/bpf/bpftool/btf.c | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/tools/bpf/bpftool/btf.c b/tools/bpf/bpftool/btf.c
index f7e5ff3586c9..89c17ea62d8e 100644
--- a/tools/bpf/bpftool/btf.c
+++ b/tools/bpf/bpftool/btf.c
@@ -37,6 +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",
};
struct btf_attach_table {
@@ -347,6 +348,23 @@ 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);
+
+
extra empty line?
+ if (json_output) {
+ jsonw_uint_field(w, "type_id", t->type);
+ if (btf_kflag(t))
+ jsonw_int_field(w, "comp_id", -1);
+ else
+ jsonw_uint_field(w, "comp_id", tag->comp_id);
+ } else if (btf_kflag(t)) {
+ printf(" type_id=%u, comp_id=-1", t->type);
+ } else {
+ printf(" type_id=%u, comp_id=%u", t->type, tag->comp_id);
+ }
here not using kflag would be more natural as well ;)
+ break;
+ }
default:
break;
}
--
2.30.2