Re: Errors compiling BPF programs from Linux selftests/bpf with GCC

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Monday, December 30th, 2024 at 4:42 PM, Alexei Starovoitov <alexei.starovoitov@xxxxxxxxx> wrote:

> 
> 
> On Mon, Dec 30, 2024 at 12:59 PM Ihor Solodrai ihor.solodrai@xxxxx wrote:
> 
> > On Monday, December 30th, 2024 at 12:36 PM, Sam James sam@xxxxxxxxxx wrote:
> > 
> > > Andrew Pinski via Gcc gcc@xxxxxxxxxxx writes:
> > > 
> > > > On Mon, Dec 30, 2024 at 12:11 PM Ihor Solodrai via Gcc gcc@xxxxxxxxxxx wrote:
> > > > 
> > > > > Hello everyone.
> > > > > 
> > > > > I picked up the work adding GCC BPF backend to BPF CI pipeline [1],
> > > > > originally done by Cupertino Miranda [2].
> > > > > 
> > > > > I encountered issues compiling BPF objects for selftests/bpf with
> > > > > recent GCC 15 snapshots. An additional test runner binary is supposed
> > > > > to be generated by tools/testing/selftests/bpf/Makefile if BPF_GCC is
> > > > > set to a directory with GCC binaries for BPF backend. The runner
> > > > > binary depends on BPF binaries, which are produced by GCC.
> > > > > 
> > > > > The first issue is compilation errors on vmlinux.h:
> > > > > 
> > > > > In file included from progs/linked_maps1.c:4:
> > > > > /ci/workspace/tools/testing/selftests/bpf/tools/include/vmlinux.h:8483:9: error: expected identifier before ‘false’
> > > > > 8483 | false = 0,
> > > > > | ^~~~~
> > > > > 
> > > > > A snippet from vmlinux.h:
> > > > > 
> > > > > enum {
> > > > > false = 0,
> > > > > true = 1,
> > > > > };
> > > > > 
> > > > > And:
> > > > > 
> > > > > /ci/workspace/tools/testing/selftests/bpf/tools/include/vmlinux.h:23539:15: error: two or more data types in declaration specifiers
> > > > > 23539 | typedef _Bool bool;
> > > > > | ^~~~
> > > > > 
> > > > > Full log at [3], and also at [4].
> > > > 
> > > > These are simple, the selftests/bpf programs need to compile with
> > > > -std=gnu17 or -std=gnu11 since GCC has changed the default to C23
> > > > which defines false and bool as keywords now and can't be redeclared
> > > > like before.
> > > 
> > > Yes, the kernel has various issues like this:
> > > https://lore.kernel.org/linux-kbuild/20241119044724.GA2246422@thelio-3990X/.
> > > 
> > > Unfortunately, not all the Makefiles correctly declare that they need
> > > gnu11.
> > > 
> > > Clang will hit issues like this too when they change default to gnu23.
> > 
> > Andrew, Sam, thank you for a swift response.
> > 
> > vmlinux.h is generated code, so for the booleans perhaps it's more
> > appropriate to generate a condition, for example:
> > 
> > #if STDC_VERSION < 202311L
> > enum {
> > false = 0,
> > true = 1,
> > };
> > #endif
> > 
> > Any drawbacks to this?
> 
> 
> By special hacking this specific enum in bpftool ?
> Feels like overkill when just adding -std=gnu17 will do.

Yeah. I've tried both the flag and a btf_dump hack today, and the hack
is indeed an overkill, assuming we don't care about generating
C23-compilant vmlinux.h. To conditionalize the declarations both the
enum and typedef _Bool have to be matched, so it's actually two hacks.
Although we do use hacks like this, noticed an interesting example
today [1].

Regardless of how the bool-related error is fixed (with STDC_VERSION
condition or std flag), I get the same int64 errors with GCC
15-20241229 when building selftests/bpf [2].

[1] https://github.com/libbpf/libbpf/blob/master/src/btf_dump.c#L1198-L1201
[2] https://gist.github.com/theihor/7e3341c5a1e1209a744994143abd9e62

> 
> > Also if vmlinux was built with GCC C23 then I assume DWARF wouldn't
> > contain the debug info for the enum, hence it wouldn't be present in
> > vmlinux.h.
> > 
> > I don't think downgrading the standard for a relatively new backend
> > makes sense, especially in the context of CI testing.
> 
> 
> I don't see why not. The flag affects the front-end while CI adds
> the test coverage to gcc bpf backend.







[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux