Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp281673ybh; Tue, 21 Jul 2020 23:58:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwpFXWNXXA3qmpfZyjDF0dRuaRnigMXuSQGooI9k9wK+eFSJ15v8JPgrUHorFxLMLO7iIw0 X-Received: by 2002:aa7:d88c:: with SMTP id u12mr20512445edq.29.1595401111968; Tue, 21 Jul 2020 23:58:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595401111; cv=none; d=google.com; s=arc-20160816; b=wjj6P7qDlK3ayH6P/ZPC4yNCH234xw1UdgfNLZbv/LdK716Ny3YEuQsyQXBVBv/aet ZjcheDR+DiJIjC0WgVEhcWl+IKZEXdoBJAf7ewTBSLNcsBhUmr5W39vNJh1jHUp89KcF JnP3Ay+RMrzXoQpaEi1ps+MaRHo7VlrSElgqOUj0qFI5E1J9ghJuunJCrf/1x/xL7Kb0 c8Ku2OpYhokTRyQJcRDtY4/uX20IkQI398044Ck9pkZl2tqHym+TeSLhO8iPHljoY5bE f6yaUZ2ggNiWkzroB+GnBOfLFZZSdwfvmhBdi44TgdxEi6o0bQlwqVT4EZS/PRqRTzVW tBEA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=zjl8jyI4JNnQLeTVzyCzHh3c+nXxWye5Cj6ubPO13J0=; b=NA3OcOCUS4bUViWsC6RcLr0rshMday82h2HbyhIQy32yh6oA0SSNc7L5ZR5gIPUwEE IOgOU6f1Y3gZOExT5scTmy7bYSDrjDMvZqSZBaxL6xIwdnpygFwUAf1wKKSuTq9km82A URuOzhnbbxczmmUC8eG19zgH7oivAplE1zz4ti5Q4oQk3IreKWp73uIVUkbLj34ZsoWL wEQEucYNZN7hAeqqCBGbJZoEvUkaMRZvB8GB7qgKJFb9lqJ4YLEeZxshLhVB7RSIsxjt Nyl9BdWIHf0C2LMMNwpQNYPjYeuA9ZMdAZpGzOnturfLMKdfNGbs7GGXP8tZx613/aTY WJxA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=GEF78V2k; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g88si14208369edd.117.2020.07.21.23.58.09; Tue, 21 Jul 2020 23:58:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=GEF78V2k; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730348AbgGVG6A (ORCPT + 99 others); Wed, 22 Jul 2020 02:58:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38208 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727882AbgGVG6A (ORCPT ); Wed, 22 Jul 2020 02:58:00 -0400 Received: from mail-qk1-x743.google.com (mail-qk1-x743.google.com [IPv6:2607:f8b0:4864:20::743]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2653FC061794; Tue, 21 Jul 2020 23:58:00 -0700 (PDT) Received: by mail-qk1-x743.google.com with SMTP id u64so990183qka.12; Tue, 21 Jul 2020 23:58:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=zjl8jyI4JNnQLeTVzyCzHh3c+nXxWye5Cj6ubPO13J0=; b=GEF78V2k9OiWRf81LyakVnVCsY+WdOadZDPh8XZnSjoWpqyVyHSBqYesBwcUVU6qn+ A2GOiIMI7D4+BCo2X43tWNGsBUTQEV15+iF25xICpC6R75QeFwAJf9f7IL+FtnY2Ynco guWA3aOcbK99jE7qNpAW14da2xrh4F+sNJ+p9hT2QIbZMXkJ4Z6vapPJLeseMS20z5ki hH/T6IJ5Prf/pBvgnXtu03h5EckJP4dmb0vjt5PknVgmm/fm7KZtKVn5sTFZ/Ya5Ntf8 37VXErV/NMpuNfETve3WI/+hiyztBgVpQioouREp/80KkRHIHv8x2KumKGBgXnqeSxCo Nzyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=zjl8jyI4JNnQLeTVzyCzHh3c+nXxWye5Cj6ubPO13J0=; b=tWEXuWAdpbLMBpQzOm77gH8+wH6UhYMoYG5ti2dPAaFQeSJ92FUpSJKODboaFVxleZ uBMZeihMIEjvz81ovYPaQuZwusMsxvNTmMfV/6o3hP0tyLPrZqUhIAWP1SXo923xY69d 29Wa3WCb4IC6HZmrTE8rQ+iXnQ+UDhWyqwUfAoDiS5Rosl1SOkAqQ2BnCaHNc2HVUFp+ QBmoi9JepLVpIF1djjXiMWVUtyRR695g7yubl3/sqAMKkPqrTc9OlVNS48U3F6VKevks DARVF3f4YnS/xdp4Tj6EAA/0ccTJmvIM7ezNU5gg0R1+lnkBTWtaC8kfLpJmzoqpiB0T ti7A== X-Gm-Message-State: AOAM5302ZnjhlvJAlgGB0G1ChHkUrox5OyUbMfp3aOyjGcGD8d0mMC5t umNiVZ9idx/Ml8rlFglA4ELyFhWGFFMu2UZjd10= X-Received: by 2002:a37:a655:: with SMTP id p82mr14245845qke.92.1595401079241; Tue, 21 Jul 2020 23:57:59 -0700 (PDT) MIME-Version: 1.0 References: <20200722054314.2103880-1-irogers@google.com> In-Reply-To: <20200722054314.2103880-1-irogers@google.com> From: Andrii Nakryiko Date: Tue, 21 Jul 2020 23:57:48 -0700 Message-ID: Subject: Re: [RFC PATCH] bpftool btf: Add prefix option to dump C To: Ian Rogers Cc: Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Song Liu , Yonghong Song , Andrii Nakryiko , John Fastabend , KP Singh , Quentin Monnet , Jakub Kicinski , Jiri Olsa , =?UTF-8?B?VG9rZSBIw7hpbGFuZC1Kw7hyZ2Vuc2Vu?= , Networking , bpf , open list , Stanislav Fomichev Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jul 21, 2020 at 10:44 PM Ian Rogers wrote: > > When bpftool dumps types and enum members into a header file for > inclusion the names match those in the original source. If the same > header file needs to be included in the original source and the bpf > program, the names of structs, unions, typedefs and enum members will > have naming collisions. vmlinux.h is not really intended to be used from user-space, because it's incompatible with pretty much any other header that declares any type. Ideally we should make this better, but that might require some compiler support. We've been discussing with Yonghong extending Clang with a compile-time check for whether some type is defined or not, which would allow to guard every type and only declare it conditionally, if it's missing. But that's just an idea at this point. Regardless, vmlinux.h is also very much Clang-specific, and shouldn't work well with GCC. Could you elaborate on the specifics of the use case you have in mind? That could help me see what might be the right solution. Thanks! > > To avoid these collisions an approach is to redeclare the header file > types and enum members, which leads to duplication and possible > inconsistencies. Another approach is to use preprocessor macros > to rename conflicting names, but this can be cumbersome if there are > many conflicts. > > This patch adds a prefix option for the dumped names. Use of this option > can avoid name conflicts and compile time errors. > > Signed-off-by: Ian Rogers > --- > .../bpf/bpftool/Documentation/bpftool-btf.rst | 7 ++++++- > tools/bpf/bpftool/btf.c | 18 ++++++++++++++--- > tools/lib/bpf/btf.h | 1 + > tools/lib/bpf/btf_dump.c | 20 +++++++++++++------ > 4 files changed, 36 insertions(+), 10 deletions(-) > [...] > diff --git a/tools/lib/bpf/btf.h b/tools/lib/bpf/btf.h > index 491c7b41ffdc..fea4baab00bd 100644 > --- a/tools/lib/bpf/btf.h > +++ b/tools/lib/bpf/btf.h > @@ -117,6 +117,7 @@ struct btf_dump; > > struct btf_dump_opts { > void *ctx; > + const char *name_prefix; > }; BTW, we can't do that, this breaks ABI. btf_dump_opts were added before we understood the problem of backward/forward compatibility of libbpf APIs, unfortunately. > > typedef void (*btf_dump_printf_fn_t)(void *ctx, const char *fmt, va_list args); > diff --git a/tools/lib/bpf/btf_dump.c b/tools/lib/bpf/btf_dump.c > index e1c344504cae..baf2b4d82e1e 100644 > --- a/tools/lib/bpf/btf_dump.c > +++ b/tools/lib/bpf/btf_dump.c [...]