From: Ihor Solodrai <ihor.solodrai@linux.dev>
To: "Andrii Nakryiko" <andrii.nakryiko@gmail.com>,
"Holger Hoffstätte" <holger@applied-asynchrony.com>
Cc: Alexei Starovoitov <alexei.starovoitov@gmail.com>,
Quentin Monnet <qmo@kernel.org>,
Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>,
Martin KaFai Lau <martin.lau@linux.dev>,
Eduard Zingerman <eddyz87@gmail.com>, 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>,
LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] bpftool: build bpf bits with -std=gnu11
Date: Tue, 6 May 2025 14:41:13 -0700 [thread overview]
Message-ID: <e5122286-68f0-4173-8549-a0705c4ca4b1@linux.dev> (raw)
In-Reply-To: <CAEf4BzYLYJtcehZhB22YsxRXZBcVnunNx-rm9CfTcDZFiY10jQ@mail.gmail.com>
On 2025-05-06 2:04 p.m., Andrii Nakryiko wrote:
> On Sun, May 4, 2025 at 3:24 AM Holger Hoffstätte
> <holger@applied-asynchrony.com> wrote:
>>
>> On 2025-05-03 04:36, Alexei Starovoitov wrote:
>>> On Fri, May 2, 2025 at 2:53 AM Holger Hoffstätte
>>> <holger@applied-asynchrony.com> wrote:
>>>>
>>>> On 2025-05-02 11:26, Quentin Monnet wrote:
>>>>> On 02/05/2025 09:57, Holger Hoffstätte wrote:
>>>>>> A gcc-15-based bpf toolchain defaults to C23 and fails to
compile various
>>>>>> kernel headers due to their use of a custom 'bool' type.
>>>>>> Explicitly using -std=gnu11 works with both clang and bpf-toolchain.
>>>>>>
>>>>>> Signed-off-by: Holger Hoffstätte <holger@applied-asynchrony.com>
>>>>>
>>>>> Thanks! I tested that it still works with clang.
>>>>>
>>>>> Acked-by: Quentin Monnet <qmo@kernel.org>
>>>>
>>>> Thanks!
>>>>
>>>>> I didn't manage to compile with gcc, though. I tried with gcc
15.1.1 but
>>>>> option '--target=bpf' is apparently unrecognised by the gcc
version on
>>>>> my setup.
>>>>>
>>>>> Out of curiosity, how did you build using gcc for the skeleton?
Was it
>>>>> enough to run "CLANG=gcc make"? Does it pass the clang-bpf-co-re
build
>>>>> probe successfully?
>>>>
>>>> I'm on Gentoo where we have a gcc-14/15 based "bpf-toolchain" package,
>>>> which is just gcc configured & packaged for the bpf target.
>>>> Our bpftool package can be built with clang (default) or without, in
>>>> which case it depend on the bpf-toolchain. The idea is to gradually
>>>> allow bpf/xdp tooling to build/run without requiring clang.
>>>>
>>>> The --target definition is conditional and removed when not using
clang:
>>>>
https://gitweb.gentoo.org/repo/gentoo.git/tree/dev-util/bpftool/bpftool-7.5.0.ebuild?id=bf70fbf7b0dc97fbc97af579954ea81a8df36113#n94
>>>>
>>>> The bug for building with the new gcc-15 based toolchain where this
>>>> patch originated is here: https://bugs.gentoo.org/955156
>>>
>>> So you're fixing this build error:
>>>
>>> bpf-unknown-none-gcc \
>>> -I. \
>>>
-I/var/tmp/portage/dev-util/bpftool-7.5.0/work/bpftool-libbpf-v7.5.0-sources/include/uapi/
>>> \
>>>
-I/var/tmp/portage/dev-util/bpftool-7.5.0/work/bpftool-libbpf-v7.5.0-sources/src/bootstrap/libbpf/include
>>> \
>>> -g -O2 -Wall -fno-stack-protector \
>>> -c skeleton/profiler.bpf.c -o profiler.bpf.o
>>> In file included from skeleton/profiler.bpf.c:3:
>>> ./vmlinux.h:5: warning: ignoring '#pragma clang attribute'
[-Wunknown-pragmas]
>>> 5 | #pragma clang attribute push
>>> (__attribute__((preserve_access_index)), apply_to = record)
>>> ./vmlinux.h:9845:9: error: cannot use keyword 'false' as
enumeration constant
>>> 9845 | false = 0,
>>> | ^~~~~
>>> ./vmlinux.h:9845:9: note: 'false' is a keyword with '-std=c23' onwards
>>> ./vmlinux.h:31137:15: error: 'bool' cannot be defined via 'typedef'
>>> 31137 | typedef _Bool bool;
>>> | ^~~~
>>>
>>> with -std=gnu11 flag and
>>
>> Yes, correct. This is the same as all over the kernel or the bpf tests
>> for handling C23. I fully understand that this particular patch is only
>> one piece of the puzzle.
>>
>
> What's the best way to detect (at compile time) whether bool, false,
> and true are treated as reserved keywords? To solve this properly
> vmlinux.h would have to be adjusted by vmlinux.h to avoid emitting
> bool/false/true *iff* compiler version/mode doesn't like that
I ran into this when adding GCC BPF to CI [1].
One can do something like:
#if __STDC_VERSION__ < 202311L
enum {
false = 0,
true = 1,
};
#endif
But in case of vmlinux.h this would require hacking bpftool, and so for
selftests/bpf we decided to pass -std=gnu11 [2].
[1]
https://lore.kernel.org/bpf/CAADnVQKNqdLW1bpvCpVV3yNizwra0cCkBnAbsNp3rTmi8WFcvQ@mail.gmail.com/
[2]
https://lore.kernel.org/bpf/20250107235813.2964472-1-ihor.solodrai@pm.me/
>
>>> ignoring an important warning ?
>>
>> Nobody is (or was) ignoring the warning - it was under discussion when
>> I posted the patch. After reaching out to Oracle to verify, we have now
>> added the BPF_NO_PRESERVE_ACCESS_INDEX define when building with
gcc-bpf;
>> this resolves the warning, just like in the bpf self-tests.
>>
>> You are right that such an addition to the in-kernel bpftool build is
>> still missing. If you have a suggestion on how best to do that via the
>> existing Makefile I'm all ears.
>>
>> As for the remaining warnings - we are also very aware of the ongoing
>> upstream work to support btf_type_tag:
>> https://gcc.gnu.org/pipermail/gcc-patches/2025-April/682340.html.
>>
>>> End result: partially functional bpftool,
>>> and users will have no idea why some features of bpftool are not
working.
>>
>> First of all this is never shipped to any users; using gcc-bpf requires
>> active opt-in by developers or users, and now also warns that such a
setup
>> may result in unexpected bugs due to ongoing work in both Linux and
bpftool.
>> Like I said before, by default everyone builds with clang and that
is also
>> true for our distributed binaries.
>>
>> If you think adding the -std=gnu11 bit is inappropriate at this time
then
>> just ignore this patch for now. Sooner or later the bpftool build
will have
>> to be adapted with BPF_CFLAGS (liek in the selftests) and hopefuilly an
>> abstracted BPF_CC so that we no longer have to pretend to be clang when
>> using gcc.
>>
>> cheers
>> Holger
next prev parent reply other threads:[~2025-05-06 21:41 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-02 8:57 Holger Hoffstätte
2025-05-02 9:26 ` Quentin Monnet
2025-05-02 9:53 ` Holger Hoffstätte
2025-05-03 2:36 ` Alexei Starovoitov
2025-05-04 10:24 ` Holger Hoffstätte
2025-05-06 21:04 ` Andrii Nakryiko
2025-05-06 21:41 ` Ihor Solodrai [this message]
2025-05-06 22:23 ` Andrii Nakryiko
2025-05-06 22:34 ` Ihor Solodrai
2025-05-06 23:34 ` Andrii Nakryiko
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=e5122286-68f0-4173-8549-a0705c4ca4b1@linux.dev \
--to=ihor.solodrai@linux.dev \
--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=eddyz87@gmail.com \
--cc=haoluo@google.com \
--cc=holger@applied-asynchrony.com \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kpsingh@kernel.org \
--cc=linux-kernel@vger.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
Powered by JetHome