From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0F538C43334 for ; Tue, 12 Jul 2022 20:47:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232902AbiGLUrq (ORCPT ); Tue, 12 Jul 2022 16:47:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50618 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231437AbiGLUro (ORCPT ); Tue, 12 Jul 2022 16:47:44 -0400 Received: from mail-pf1-x44a.google.com (mail-pf1-x44a.google.com [IPv6:2607:f8b0:4864:20::44a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7C77831222 for ; Tue, 12 Jul 2022 13:47:42 -0700 (PDT) Received: by mail-pf1-x44a.google.com with SMTP id i21-20020aa79095000000b00528bd947f66so2680012pfa.18 for ; Tue, 12 Jul 2022 13:47:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=UmaN+lg1gVY00nS/FFRqdUXBbU3SwpvZPAY4iW8kINU=; b=JahOGRhQjUoYH60LNMTwoBdEccmWhGvwskp4rfCVpx6hGwVorvPWF/E7+XyBzuUWYy Aae2gHO54dT9ri42KU80XMdFRDcvraWnpX7VleGfAMo6DcWbXADZyPDdHv6Y7DLDmW+K ti8d8wt6YR8zc9yoDpHpzewPVVOWaZgY7KifsdyYRPSk+9hSAR4mo5Yd0D1GOwjeJ5ka gSDiyoXDx0mNdITZDRaTBwYhL1siKUSvqo7v/hXR+ry1w9u15WpBrpLngGuH7g0sO24q gMXBqqTJYlkB4LR8QlHdRxNk7uGJFWXW+Rj4qbA7Ce+TbJQEizGslfzLpyfS0vtzpcH6 G5+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=UmaN+lg1gVY00nS/FFRqdUXBbU3SwpvZPAY4iW8kINU=; b=MVFrgZOzA54avTVN7+/YpMQHVYye2qyJ+Og3p+adKYm6JnVKGov8eZSENUVKb/QI5u 0vwY28eDhT0PnybWciN2YAPeCDY+JIqCI+lhZkW73FHpkPpHxb5CcH7VkTGaSRhT6y90 nMD8E9xDrpfyeVuioOfo/lT5gYIGoQJz4S0S4AI1m90YbfGR2bzbqDRLN7JE/dewK+ik iY/nxZ2aiyxxW6LC+ecM/BP5RxWGyepb0pLiIC8g3gXDFBVg6lkpLvRkSk3anx5AOb2+ eQdpgZjzF6oMXcCDBP1Hbm8ohs7JNWB2ETCClqOzWe7fDBcuH2fr7RGlFEB1z+rSys0r vVwA== X-Gm-Message-State: AJIora+a9ly7qzt89tJZnuRODptOlUXjCDLM8Yi+m3oDti5CAI5QP586 CKKcETp0oiDX3+VV0rKMBYi5h3U= X-Google-Smtp-Source: AGRyM1vVHUMGTuqvwkQOaBRLL4govc9MSnFQyvufa1aFmhnFGVlueCTSuzGycWTeB2CgBbUZ6UPiu14= X-Received: from sdf.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5935]) (user=sdf job=sendgmr) by 2002:a17:903:20d4:b0:16b:da9d:975a with SMTP id i20-20020a17090320d400b0016bda9d975amr25520398plb.119.1657658862026; Tue, 12 Jul 2022 13:47:42 -0700 (PDT) Date: Tue, 12 Jul 2022 13:47:40 -0700 In-Reply-To: <20220712184225.52429-2-flaniel@linux.microsoft.com> Message-Id: Mime-Version: 1.0 References: <20220712184225.52429-1-flaniel@linux.microsoft.com> <20220712184225.52429-2-flaniel@linux.microsoft.com> Subject: Re: [RFC PATCH v1 1/1] bpftool: Add generating command to C dumped file. From: sdf@google.com To: Francis Laniel Cc: bpf@vger.kernel.org, Quentin Monnet , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Hao Luo , Jiri Olsa , open list Content-Type: text/plain; charset="UTF-8"; format=flowed; delsp=yes Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 > --- > 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