From: Eduard Zingerman <eddyz87@gmail.com>
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: Andrii Nakryiko <andrii.nakryiko@gmail.com>,
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:19:31 -0800 [thread overview]
Message-ID: <4d3972ec6951b3c02f79def0215e5bb4fc70aba4.camel@gmail.com> (raw)
In-Reply-To: <CAADnVQL=2m9NHjr0zbMoDyha=6sBFd69=1QRdxSCKYhEONTmaw@mail.gmail.com>
On Wed, 2025-12-17 at 15:34 -0800, Alexei Starovoitov wrote:
> On Wed, Dec 17, 2025 at 2:47 PM Eduard Zingerman <eddyz87@gmail.com> wrote:
> >
> > > $ cat ms-ext-test2.c
> > > struct foo {
> > > int a;
> > > } __attribute__((preserve_access_index));
> > >
> > > struct bar {
> > > struct foo;
> > > } __attribute__((preserve_access_index));
> > >
> > > int buz(struct bar *bar) {
> > > return bar->a;
> > > }
> > >
> > > $ clang -O2 -g -fms-extensions --target=bpf -c ms-ext-test2.c
> > > ms-ext-test2.c:6:3: warning: anonymous structs are a Microsoft extension [-Wmicrosoft-anon-tag]
> > > 6 | struct foo;
> > > | ^~~~~~~~~~
> > > 1 warning generated.
> > >
> > > $ llvm-objdump -Sdr ms-ext-test2.o
> > >
> > > ms-ext-test2.o: file format elf64-bpf
> > >
> > > Disassembly of section .text:
> > >
> > > 0000000000000000 <buz>:
> > > ; return bar->a;
> > > 0: 61 10 00 00 00 00 00 00 w0 = *(u32 *)(r1 + 0x0)
> > > 0000000000000000: CO-RE <byte_off> [2] struct bar::<anon 0>.a (0:0:0)
> > > 1: 95 00 00 00 00 00 00 00 exit
> > >
> > > Note the "<anon 0>" in the relocation.
> > > It appears that we loose no information if structures are unrolled.
>
> Forgot to mention the CORE concern earlier...
> Does the above work with current logic in relo_core.c ?
> If not, we should definitely unconditionally unroll
> to avoid fixing CORE.
I think there might be an issue with CO-RE.
Here is an example:
struct foo {
int a;
} __attribute__((preserve_access_index));
struct bar {
#ifdef USE_MS
struct foo;
#else
struct { int a; };
#endif
} __attribute__((preserve_access_index));
int buz(struct bar *bar) {
return bar->a;
}
Here is what I get with USE_MS:
$ llvm-objdump -Sdr ms-ext-test2.o
ms-ext-test2.o: file format elf64-bpf
Disassembly of section .text:
0000000000000000 <buz>:
; return bar->a;
0: 61 10 00 00 00 00 00 00 w0 = *(u32 *)(r1 + 0x0)
0000000000000000: CO-RE <byte_off> [2] struct bar::<anon 0>.a (0:0:0)
1: 95 00 00 00 00 00 00 00 exit
$ bpftool btf dump file ms-ext-test2.o
[1] PTR '(anon)' type_id=2
[2] STRUCT 'bar' size=4 vlen=1
'(anon)' type_id=3 bits_offset=0
[3] STRUCT 'foo' size=4 vlen=1
'a' type_id=4 bits_offset=0
[4] INT 'int' size=4 bits_offset=0 nr_bits=32 encoding=SIGNED
[5] FUNC_PROTO '(anon)' ret_type_id=4 vlen=1
'bar' type_id=1
[6] FUNC 'buz' type_id=5 linkage=global
And here is without USE_MS:
$ llvm-objdump -Sdr ms-ext-test2.o
ms-ext-test2.o: file format elf64-bpf
Disassembly of section .text:
0000000000000000 <buz>:
; return bar->a;
0: 61 10 00 00 00 00 00 00 w0 = *(u32 *)(r1 + 0x0)
0000000000000000: CO-RE <byte_off> [2] struct bar::<anon 0>.a (0:0:0)
1: 95 00 00 00 00 00 00 00 exit
$ bpftool btf dump file ms-ext-test2.o
[1] PTR '(anon)' type_id=2
[2] STRUCT 'bar' size=4 vlen=1
'(anon)' type_id=3 bits_offset=0
[3] STRUCT '(anon)' size=4 vlen=1
'a' type_id=4 bits_offset=0
[4] INT 'int' size=4 bits_offset=0 nr_bits=32 encoding=SIGNED
[5] FUNC_PROTO '(anon)' ret_type_id=4 vlen=1
'bar' type_id=1
[6] FUNC 'buz' type_id=5 linkage=global
So, with USE_MS the relocation captures the offset inside 'struct foo'.
And this is important for CO-RE offsets resolution.
So unrolling structures is actually a problem.
next prev parent reply other threads:[~2025-12-18 0:19 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 [this message]
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
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=4d3972ec6951b3c02f79def0215e5bb4fc70aba4.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