Skip to content

libbpf: Render decl_tags in btf_dump

Ihor Solodrai bpf 2 versions – Applied

Status from this message: This series was applied to bpf/bpf-next.git (master)

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest5 patches 0 repliesApplied 5/5
  2. v14 patches 11 repliesSuperseded

Changes in v2 from the cover letter

* 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)

Patches in v2 All 5 applied

#Subject and filesSizeRepliesApplied
1/5libbpf: Walk types in btf_dump_resize(), not in mark_referenced()tools/lib/bpf/btf_dump.c+60 -620 repliesApplied
2/5libbpf: Render decl_tags in btf_dumptools/lib/bpf/btf_dump.c+93 -10 repliesApplied
3/5selftests/bpf: Add ASSERT_TEXT_EQ()tools/testing/selftests/bpf/prog_tests/bpftool_btf_dump.c tools/testing/selftests/bpf/prog_tests/btf_dump.c tools/testing/selftests/bpf/test_progs.h+7 -110 repliesApplied
4/5selftests/bpf: Test btf_dump rendering of decl_tagstools/testing/selftests/bpf/prog_tests/btf_dump.c+275 -10 repliesApplied
5/5selftests/bpf: Show the tag kflag in the raw BTF dump helpertools/testing/selftests/bpf/btf_helpers.c tools/testing/selftests/bpf/prog_tests/btf_write.c+41 -30 repliesApplied

Reviews trailers per patch

4 of 5 patches have a Reviewed-by or Acked-by.

PatchEduard Zingerman
1/5A-b
2/5A-b
3/5
4/5A-b
5/5A-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v2 thread

Cover letter [PATCH bpf-next v2 0/5] libbpf: Render decl_tags in btf_dump

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/[email protected]/

---

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/[email protected]/

---

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

Signature · 1 line
2.50.1