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 E2FBAC43334 for ; Tue, 12 Jul 2022 20:47:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231599AbiGLUro (ORCPT ); Tue, 12 Jul 2022 16:47:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50616 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229700AbiGLUro (ORCPT ); Tue, 12 Jul 2022 16:47:44 -0400 Received: from mail-pf1-x449.google.com (mail-pf1-x449.google.com [IPv6:2607:f8b0:4864:20::449]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 787CF2F664 for ; Tue, 12 Jul 2022 13:47:42 -0700 (PDT) Received: by mail-pf1-x449.google.com with SMTP id a127-20020a624d85000000b00525950b1feeso2662622pfb.0 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=ao3jamc9cKm7rv246gIK5/nkrD9u9WsbmY8bdmL6p0riadTwLE1b5xzu6PtvBqCj0S xb03e6oNM+1bt7mcUz7C4Mh7rjiHz7jckUBfXWZEjxywpy4+5fcv7pKiRPYypdH2BE39 KJ59g+4r0qZZ/XrJ/9sMt4+c+ursVkkhucz3gffGsv7QRLZFXttSbwsHq9d+bQKV4vja 2CZ+8yb5RiU86xLe73jNZJXMSEyUuFExGypBXRUCQehlXtvOTlot5q0QnlC8e6JghPd/ SRdd/BVyqcRG9t70xXb260Z+QsNqHkkfvrtfR1goBNGrlrzdPOkKCpx/VdL9d3i11sMw S4eg== X-Gm-Message-State: AJIora9Fgx9eANBLp3lqlgbYXgwKaFl7E2DFWuv/sZ+vtzPx4a3Ktdk1 p1TT29LzR56IDkSK9aJOxOK/Evo= 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: bpf@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