BPF List
 help / color / mirror / Atom feed
From: Eduard Zingerman <eddyz87@gmail.com>
To: Andrii Nakryiko <andrii.nakryiko@gmail.com>,
	Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: Alan Maguire <alan.maguire@oracle.com>,
	Quentin Monnet <qmo@kernel.org>,
	Andrii Nakryiko <andrii@kernel.org>,
	Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	 Martin KaFai Lau <martin.lau@linux.dev>,
	Song Liu <song@kernel.org>,
	Yonghong Song <yonghong.song@linux.dev>,
	John Fastabend <john.fastabend@gmail.com>,
	KP Singh <kpsingh@kernel.org>,
	Stanislav Fomichev	 <sdf@fomichev.me>,
	Hao Luo <haoluo@google.com>, Jiri Olsa <jolsa@kernel.org>,
	bpf	 <bpf@vger.kernel.org>
Subject: Re: [PATCH bpf-next 1/2] libbpf: add option to force-anonymize nested structs for BTF dump
Date: Wed, 17 Dec 2025 16:49:07 -0800	[thread overview]
Message-ID: <4249d7ea924491da5d95f6dab60c7cf4da742bae.camel@gmail.com> (raw)
In-Reply-To: <CAEf4BzaRxvM9C2+FvUViJqFJPTMTv6uoWc8i1taEzijdJOddwg@mail.gmail.com>

On Wed, 2025-12-17 at 15:52 -0800, Andrii Nakryiko wrote:
> On Wed, Dec 17, 2025 at 1:27 PM Alexei Starovoitov
> <alexei.starovoitov@gmail.com> wrote:
> > 
> > On Wed, Dec 17, 2025 at 1:02 PM Andrii Nakryiko
> > <andrii.nakryiko@gmail.com> wrote:
> > > 
> > > On Wed, Dec 17, 2025 at 12:50 PM Alan Maguire <alan.maguire@oracle.com> wrote:
> > > > 
> > > > On 17/12/2025 19:35, Eduard Zingerman wrote:
> > > > > On Wed, 2025-12-17 at 11:34 -0800, Eduard Zingerman wrote:
> > > > > > On Wed, 2025-12-17 at 18:41 +0000, Alan Maguire wrote:
> > > > > > 
> > > > > > [...]
> > > > > > 
> > > > > > > So maybe the best we can do here is something like the following at the top
> > > > > > > of vmlinux.h:
> > > > > > > 
> > > > > > > #ifndef BPF_USE_MS_EXTENSIONS
> > > > > > > #if __has_builtin(__builtin_FUNCSIG) || defined(_MSC_EXTENSIONS)
> > > > > > > #define BPF_USE_MS_EXTENSIONS
> > > > > > > #endif
> > > > > > > #endif
> > > > > > > 
> > > > > > > ...and then guard using #ifdef BPF_USE_MS_EXTENSIONS
> > > > > > > 
> > > > > > > That will work on clang and perhaps at some point work on gcc, but also
> > > > > > > gives the user the option to supply a macro to force use in cases where
> > > > > > > there is no detection available.
> > > > > > 
> > > > > > Are we sure we need such flexibility?
> > > > > > Maybe just stick with current implementation and unroll the structures
> > > > > > unconditionally?
> > > > > 
> > > > > I mean, the point of the extension is to make the code smaller.
> > > > > But here we are expanding it instead, so why bother?
> > > > 
> > > > Yeah, I'm happy either way; if we have agreement that we just use the nested anon
> > > > struct without macro complications I'll send an updated patch.
> > > 
> > > There is a little bit of semantic meaning being lost when we inline
> > > the struct, but I guess that can't be helped. Let's just
> > > unconditionally inline then. Still better than having extra emit
> > > option, IMO.
> > 
> > tbh I'm concerned about information loss.
> > 
> > If it's not too hard I would do
> > #ifndef BPF_USE_MS_EXTENSIONS
> > #if __has_builtin(__builtin_FUNCSIG)
> > #define BPF_USE_MS_EXTENSIONS
> > #endif
> > 
> 
> Concert I have with this is that we'd need to hard-code this
> bpftool/vmlinux.h-specific #ifdef/#else/#endif logic (with arbitrary
> and custom BPF_USE_MS_EXTENSIONS define use) for -fms-extension
> handling inside generic libbpf btf_dump API, which is not supposed to
> be vmlinux.h specific.
> 
> Wasn't there a way to basically declare -fms-extensions using #pragma
> inside vmlinux.h itself? If yes, what's the problem with using it? Why
> do we need to work-around anything at all then?

Can't find anything relevant in [1] or [2].
[1] https://clang.llvm.org/docs/LanguageExtensions.html
[2] https://clang.llvm.org/docs/UsersManual.html

Google's LLM doesn't know about such pragmas either.

> > and it will guarantee to work for clang while gcc will have structs inlined.
> > 
> > In one of the clang selftests they have this comment:
> > clang/test/Preprocessor/feature_tests.c:
> > #elif __has_builtin(__builtin_FUNCSIG)
> > #error Clang should not have this without '-fms-extensions'
> > #endif
> > 
> > so this detection is a known approach.

  reply	other threads:[~2025-12-18  0:49 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-16 17:18 [PATCH bpf-next 0/2] Handle -fms-extension in kernel structs Alan Maguire
2025-12-16 17:18 ` [PATCH bpf-next 1/2] libbpf: add option to force-anonymize nested structs for BTF dump Alan Maguire
2025-12-16 19:00   ` Eduard Zingerman
2025-12-16 19:08     ` Andrii Nakryiko
2025-12-16 19:46     ` Eduard Zingerman
2025-12-17 16:06       ` Alan Maguire
2025-12-17 16:12         ` Alexei Starovoitov
2025-12-17 17:06           ` Andrii Nakryiko
2025-12-17 17:33             ` Alan Maguire
2025-12-17 17:52               ` Alexei Starovoitov
2025-12-17 18:41                 ` Alan Maguire
2025-12-17 19:34                   ` Eduard Zingerman
2025-12-17 19:35                     ` Eduard Zingerman
2025-12-17 20:50                       ` Alan Maguire
2025-12-17 21:02                         ` Andrii Nakryiko
2025-12-17 21:27                           ` Alexei Starovoitov
2025-12-17 22:34                             ` Eduard Zingerman
2025-12-17 22:47                               ` Eduard Zingerman
2025-12-17 23:34                                 ` Alexei Starovoitov
2025-12-18  0:19                                   ` Eduard Zingerman
2025-12-18  0:39                                     ` Alexei Starovoitov
2025-12-18  0:50                                       ` Eduard Zingerman
2025-12-17 23:52                             ` Andrii Nakryiko
2025-12-18  0:49                               ` Eduard Zingerman [this message]
2025-12-17 17:10         ` Andrii Nakryiko
2025-12-16 17:18 ` [PATCH bpf-next 2/2] bpftool: force-anonymize structs to avoid need for -fms-extension Alan Maguire
2025-12-16 19:20 ` [PATCH bpf-next 0/2] Handle -fms-extension in kernel structs Song Liu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4249d7ea924491da5d95f6dab60c7cf4da742bae.camel@gmail.com \
    --to=eddyz87@gmail.com \
    --cc=alan.maguire@oracle.com \
    --cc=alexei.starovoitov@gmail.com \
    --cc=andrii.nakryiko@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=haoluo@google.com \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kpsingh@kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=qmo@kernel.org \
    --cc=sdf@fomichev.me \
    --cc=song@kernel.org \
    --cc=yonghong.song@linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox