[RFC bpf-next 05/13] bpftool: support displaying raw split BTF using base reference BTF as base

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



If no base BTF can be found, fall back to checking for the .BTF.base_ref
section and use it to display raw split BTF.  Note that C format output
is not supported for base reference BTF as structs and unions are generally
represented as FWDs.

Signed-off-by: Alan Maguire <alan.maguire@xxxxxxxxxx>
---
 tools/bpf/bpftool/btf.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/tools/bpf/bpftool/btf.c b/tools/bpf/bpftool/btf.c
index 91fcb75babe3..f1e0ea06f05f 100644
--- a/tools/bpf/bpftool/btf.c
+++ b/tools/bpf/bpftool/btf.c
@@ -552,6 +552,7 @@ static int do_dump(int argc, char **argv)
 	struct btf *btf = NULL, *base = NULL;
 	__u32 root_type_ids[2];
 	int root_type_cnt = 0;
+	bool c_compat = true;
 	bool dump_c = false;
 	__u32 btf_id = -1;
 	const char *src;
@@ -631,6 +632,21 @@ static int do_dump(int argc, char **argv)
 			base = get_vmlinux_btf_from_sysfs();
 
 		btf = btf__parse_split(*argv, base ?: base_btf);
+		/* Finally check for presence of "base reference" base BTF -
+		 * this will allow dumping in raw but not C format, since
+		 * base reference BTF will not contain fully-described
+		 * structs/unions.
+		 */
+		if (!btf && !base && !base_btf) {
+			LIBBPF_OPTS(btf_parse_opts, optp);
+
+			optp.btf_sec = BTF_BASE_REF_ELF_SEC;
+			base_btf = btf__parse_opts(*argv, &optp);
+			if (base_btf)
+				btf = btf__parse_split(*argv, base_btf);
+			if (btf)
+				c_compat = false;
+		}
 		if (!btf) {
 			err = -errno;
 			p_err("failed to load BTF from %s: %s",
@@ -686,6 +702,11 @@ static int do_dump(int argc, char **argv)
 	}
 
 	if (dump_c) {
+		if (!c_compat) {
+			p_err("Cannot represent split BTF with base reference BTF in C format");
+			err = -ENOTSUP;
+			goto done;
+		}
 		if (json_output) {
 			p_err("JSON output for C-syntax dump is not supported");
 			err = -ENOTSUP;
-- 
2.39.3





[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux