From: Ihor Solodrai <ihor.solodrai@linux.dev>
To: Alexei Starovoitov <ast@kernel.org>,
Andrii Nakryiko <andrii@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Eduard Zingerman <eddyz87@gmail.com>,
Kumar Kartikeya Dwivedi <memxor@gmail.com>
Cc: bpf@vger.kernel.org, Alan Maguire <alan.maguire@oracle.com>
Subject: [PATCH bpf-next v2 5/5] selftests/bpf: Show the tag kflag in the raw BTF dump helper
Date: Tue, 29 Sep 2026 16:46:08 -0700 [thread overview]
Message-ID: <20260929234608.48503-6-ihor.solodrai@linux.dev> (raw)
In-Reply-To: <20260929234608.48503-1-ihor.solodrai@linux.dev>
A kflag on BTF_KIND_DECL_TAG or BTF_KIND_TYPE_TAG means the tag string
is an __attribute__ list rather than a btf_decl_tag()/btf_type_tag()
argument. fprintf_btf_type_raw() did not print it, so a tag added with
btf__add_decl_tag() and an attribute added with btf__add_decl_attr()
dumped identically apart from their type IDs.
Print " kflag=1" for those two kinds, only when the flag is set, so no
existing expected string changes.
Add a btf_write subtest for btf__add_decl_attr() and
btf__add_type_attr().
Signed-off-by: Ihor Solodrai <ihor.solodrai@linux.dev>
Acked-by: Eduard Zingerman <eddyz87@gmail.com>
---
tools/testing/selftests/bpf/btf_helpers.c | 10 ++++--
.../selftests/bpf/prog_tests/btf_write.c | 34 +++++++++++++++++++
2 files changed, 41 insertions(+), 3 deletions(-)
diff --git a/tools/testing/selftests/bpf/btf_helpers.c b/tools/testing/selftests/bpf/btf_helpers.c
index 85a4d15d1dd1..e04b61c08cd8 100644
--- a/tools/testing/selftests/bpf/btf_helpers.c
+++ b/tools/testing/selftests/bpf/btf_helpers.c
@@ -114,9 +114,12 @@ int fprintf_btf_type_raw(FILE *out, const struct btf *btf, __u32 id)
case BTF_KIND_VOLATILE:
case BTF_KIND_RESTRICT:
case BTF_KIND_TYPEDEF:
- case BTF_KIND_TYPE_TAG:
fprintf(out, " type_id=%u", t->type);
break;
+ case BTF_KIND_TYPE_TAG:
+ fprintf(out, " type_id=%u%s", t->type,
+ btf_kflag(t) ? " kflag=1" : "");
+ break;
case BTF_KIND_ARRAY: {
const struct btf_array *arr = btf_array(t);
@@ -203,8 +206,9 @@ int fprintf_btf_type_raw(FILE *out, const struct btf *btf, __u32 id)
fprintf(out, " size=%u", t->size);
break;
case BTF_KIND_DECL_TAG:
- fprintf(out, " type_id=%u component_idx=%d",
- t->type, btf_decl_tag(t)->component_idx);
+ fprintf(out, " type_id=%u component_idx=%d%s",
+ t->type, btf_decl_tag(t)->component_idx,
+ btf_kflag(t) ? " kflag=1" : "");
break;
case BTF_KIND_LOC_PARAM: {
struct btf_loc_param *p = btf_loc_param(t);
diff --git a/tools/testing/selftests/bpf/prog_tests/btf_write.c b/tools/testing/selftests/bpf/prog_tests/btf_write.c
index 5c84723cf254..3bed3a28c06a 100644
--- a/tools/testing/selftests/bpf/prog_tests/btf_write.c
+++ b/tools/testing/selftests/bpf/prog_tests/btf_write.c
@@ -606,6 +606,38 @@ static void test_btf_add_btf_split()
btf__free(base);
}
+static void test_btf_attrs(void)
+{
+ struct btf *btf;
+
+ btf = btf__new_empty();
+ if (!ASSERT_OK_PTR(btf, "new_empty"))
+ return;
+
+ btf__add_int(btf, "int", 4, BTF_INT_SIGNED);
+ btf__add_struct(btf, "s", 4);
+ btf__add_field(btf, "f", 1, 0, 0);
+
+ btf__add_decl_tag(btf, "tag", 2, -1);
+ btf__add_decl_attr(btf, "tag", 2, -1);
+ btf__add_decl_attr(btf, "member_attr", 2, 0);
+ btf__add_type_tag(btf, "tag", 1);
+ btf__add_type_attr(btf, "tag", 1);
+
+ VALIDATE_RAW_BTF(
+ btf,
+ "[1] INT 'int' size=4 bits_offset=0 nr_bits=32 encoding=SIGNED",
+ "[2] STRUCT 's' size=4 vlen=1\n"
+ "\t'f' type_id=1 bits_offset=0",
+ "[3] DECL_TAG 'tag' type_id=2 component_idx=-1",
+ "[4] DECL_TAG 'tag' type_id=2 component_idx=-1 kflag=1",
+ "[5] DECL_TAG 'member_attr' type_id=2 component_idx=0 kflag=1",
+ "[6] TYPE_TAG 'tag' type_id=1",
+ "[7] TYPE_TAG 'tag' type_id=1 kflag=1");
+
+ btf__free(btf);
+}
+
void test_btf_write()
{
if (test__start_subtest("btf_add"))
@@ -614,4 +646,6 @@ void test_btf_write()
test_btf_add_btf();
if (test__start_subtest("btf_add_btf_split"))
test_btf_add_btf_split();
+ if (test__start_subtest("btf_attrs"))
+ test_btf_attrs();
}
--
2.50.1
next prev parent reply other threads:[~2026-09-29 23:46 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-29 23:46 [PATCH bpf-next v2 0/5] libbpf: Render decl_tags in btf_dump Ihor Solodrai
2026-09-29 23:46 ` [PATCH bpf-next v2 1/5] libbpf: Walk types in btf_dump_resize(), not in mark_referenced() Ihor Solodrai
2026-09-29 23:46 ` [PATCH bpf-next v2 2/5] libbpf: Render decl_tags in btf_dump Ihor Solodrai
2026-09-29 23:46 ` [PATCH bpf-next v2 3/5] selftests/bpf: Add ASSERT_TEXT_EQ() Ihor Solodrai
2026-09-29 23:46 ` [PATCH bpf-next v2 4/5] selftests/bpf: Test btf_dump rendering of decl_tags Ihor Solodrai
2026-09-29 23:46 ` Ihor Solodrai [this message]
2026-09-30 9:10 ` [PATCH bpf-next v2 0/5] libbpf: Render decl_tags in btf_dump patchwork-bot+netdevbpf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260929234608.48503-6-ihor.solodrai@linux.dev \
--to=ihor.solodrai@linux.dev \
--cc=alan.maguire@oracle.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=memxor@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.