[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <Ys3d7LCN8yATY9az@google.com>
Date: Tue, 12 Jul 2022 13:47:40 -0700
From: sdf@...gle.com
To: Francis Laniel <flaniel@...ux.microsoft.com>
Cc: bpf@...r.kernel.org, Quentin Monnet <quentin@...valent.com>,
Alexei Starovoitov <ast@...nel.org>,
Daniel Borkmann <daniel@...earbox.net>,
Andrii Nakryiko <andrii@...nel.org>,
Martin KaFai Lau <martin.lau@...ux.dev>,
Song Liu <song@...nel.org>, Yonghong Song <yhs@...com>,
John Fastabend <john.fastabend@...il.com>,
KP Singh <kpsingh@...nel.org>, Hao Luo <haoluo@...gle.com>,
Jiri Olsa <jolsa@...nel.org>,
open list <linux-kernel@...r.kernel.org>
Subject: Re: [RFC PATCH v1 1/1] bpftool: Add generating command to C dumped file.
On 07/12, Francis Laniel wrote:
> This commit adds the following lines to file generated by dump:
> /*
> * File generated by bpftool using:
> * bpftool btf dump file /sys/kernel/btf/vmlinux format c
> * DO NOT EDIT.
> */
> This warns users to not edit the file and documents the command used to
> generate the file.
> Signed-off-by: Francis Laniel <flaniel@...ux.microsoft.com>
> ---
> tools/bpf/bpftool/btf.c | 16 ++++++++++++++--
> 1 file changed, 14 insertions(+), 2 deletions(-)
> diff --git a/tools/bpf/bpftool/btf.c b/tools/bpf/bpftool/btf.c
> index 7e6accb9d9f7..eecfc27370c3 100644
> --- a/tools/bpf/bpftool/btf.c
> +++ b/tools/bpf/bpftool/btf.c
> @@ -415,7 +415,8 @@ static void __printf(2, 0) btf_dump_printf(void *ctx,
> }
> static int dump_btf_c(const struct btf *btf,
> - __u32 *root_type_ids, int root_type_cnt)
> + __u32 *root_type_ids, int root_type_cnt,
> + int argc, char **argv)
> {
> struct btf_dump *d;
> int err = 0, i;
> @@ -425,6 +426,14 @@ static int dump_btf_c(const struct btf *btf,
> if (err)
> return err;
> + printf("/*\n");
> + printf(" * File generated by bpftool using:\n");
> + printf(" * bpftool btf dump");
[..]
> + for (i = 0; i < argc; i++)
> + printf(" %s", argv[i]);
Do we really need that complexity to preserve the arguments?
For skeletons we're simply doing:
/* THIS FILE IS AUTOGENERATED BY BPFTOOL! */
So probably the same should be fine here?
Also, while at it, might be worth adding SPDX license comment? So let's
align with whatever we have in gen.c ?
> + printf("\n");
> + printf(" * DO NOT EDIT.\n");
> + printf(" */\n");
> printf("#ifndef __VMLINUX_H__\n");
> printf("#define __VMLINUX_H__\n");
> printf("\n");
> @@ -507,8 +516,10 @@ static bool btf_is_kernel_module(__u32 btf_id)
> static int do_dump(int argc, char **argv)
> {
> struct btf *btf = NULL, *base = NULL;
> + char **orig_argv = argv;
> __u32 root_type_ids[2];
> int root_type_cnt = 0;
> + int orig_argc = argc;
> bool dump_c = false;
> __u32 btf_id = -1;
> const char *src;
> @@ -649,7 +660,8 @@ static int do_dump(int argc, char **argv)
> err = -ENOTSUP;
> goto done;
> }
> - err = dump_btf_c(btf, root_type_ids, root_type_cnt);
> + err = dump_btf_c(btf, root_type_ids, root_type_cnt,
> + orig_argc, orig_argv);
> } else {
> err = dump_btf_raw(btf, root_type_ids, root_type_cnt);
> }
> --
> 2.25.1
Powered by blists - more mailing lists