BPF List
 help / color / mirror / Atom feed
* [PATCH bpf-next v2 0/5] libbpf: Render decl_tags in btf_dump
@ 2026-09-29 23:46 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
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Ihor Solodrai @ 2026-09-29 23:46 UTC (permalink / raw)
  To: Alexei Starovoitov, Andrii Nakryiko, Daniel Borkmann,
	Eduard Zingerman, Kumar Kartikeya Dwivedi
  Cc: bpf, Alan Maguire

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


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-09-30  9:10 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox