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 0/5] libbpf: Render decl_tags in btf_dump
Date: Tue, 29 Sep 2026 16:46:03 -0700 [thread overview]
Message-ID: <20260929234608.48503-1-ihor.solodrai@linux.dev> (raw)
BTF supports arbitrary __attribute__ encoding via decl tags and type
tags [1]. However btf_dump facility only outputs the attributes
encoded in BTF as type tags, which was implemented in commit
2019c58318b8 ("libbpf: Check the kflag of type tags in btf_dump").
BTF_KIND_DECL_TAG has been left out of btf_dump entirely, independent
of the kflag value. An attribute a BTF producer encoded is silently
dropped from the C output.
Implement decl_tag support in btf_dump. The btf_dump limits rendered
BTF types to records, record members and typedefs. Other types,
particularly functions, are deliberately skipped. Therefore decl_tag
rendering works only for the same subset of target types.
To be efficient, decl_tag dump support requires a reverse index from
the target type id to the list of tags pointing at it.
With decl_tag dump support, provided a validly constructed BTF, it is
now possible to obtain C-syntax output like the following example:
struct foo {
int a __attribute__((bar));
int b: 3 __attribute__((bar));
} __attribute__((bar));
typedef struct { ... } __attribute__((bar)) foo_t __attribute__((baz));
This closes a generic gap in btf_dump, which silently dropped every
decl tag it was given. The in-tree consumer is:
bpftool btf dump ... format c
A BPF object now keeps its member tags, such as the "contains:" tags.
[1] https://lore.kernel.org/bpf/20250130201239.1429648-1-ihor.solodrai@linux.dev/
---
v1->v2:
* index all decl tags in btf_dump (Andrii)
* roll the decl tag count back on resize errors (Alexei, sashiko)
* new patch #3 with the ASSERT_TEXT_EQ() text-comparison helper (Eduard)
* fold the incremental subtest into test_btf_dump_incremental (Eduard)
* cut test_btf_attrs down to bare API calls plus VALIDATE_RAW_BTF,
with no BTF_*_ENC macros (sashiko, Eduard)
v1: https://lore.kernel.org/bpf/20260917012037.1396254-1-ihor.solodrai@linux.dev/
---
Ihor Solodrai (5):
libbpf: Walk types in btf_dump_resize(), not in mark_referenced()
libbpf: Render decl_tags in btf_dump
selftests/bpf: Add ASSERT_TEXT_EQ()
selftests/bpf: Test btf_dump rendering of decl_tags
selftests/bpf: Show the tag kflag in the raw BTF dump helper
tools/lib/bpf/btf_dump.c | 214 +++++++++----
tools/testing/selftests/bpf/btf_helpers.c | 10 +-
.../bpf/prog_tests/bpftool_btf_dump.c | 6 +-
.../selftests/bpf/prog_tests/btf_dump.c | 285 +++++++++++++++++-
.../selftests/bpf/prog_tests/btf_write.c | 34 +++
tools/testing/selftests/bpf/test_progs.h | 3 +
6 files changed, 475 insertions(+), 77 deletions(-)
base-commit: cc6010e6e5cbe1f743d3011991041f227d976a5e
--
2.50.1
next 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 Ihor Solodrai [this message]
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 ` [PATCH bpf-next v2 5/5] selftests/bpf: Show the tag kflag in the raw BTF dump helper Ihor Solodrai
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-1-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).