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

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

 



> Hi everyone.
>
> I built and ran selftests/bpf with GCC 15-20241229, and would like to
> share my findings.
>
> Building required small adjustments in the Makefile, besides -std=gnu17
>
> With the following change we can mitigate int64_t issue:
>
> +progs/test_cls_redirect.c-CFLAGS := -nostdinc
> +progs/test_cls_redirect_dynptr.c-CFLAGS := -nostdinc
> +progs/test_cls_redirect_subprogs.c-CFLAGS := -nostdinc

These shouldn' be necessary anymore after the change in
https://gcc.gnu.org/pipermail/gcc-patches/2025-January/672508.html

> Then, the compiler complains about an uninitialized variable in
> progs/verifier_bpf_fastcall.c and progs/verifier_search_pruning.c
> (full log at [1]):
>
>     In file included from progs/verifier_bpf_fastcall.c:7:
>     progs/verifier_bpf_fastcall.c: In function ‘may_goto_interaction’:
>     progs/bpf_misc.h:153:42: error: ‘<Uc098>’ is used uninitialized [-Werror=uninitialized]
>       153 | #define __imm_insn(name, expr) [name]"i"(*(long *)&(expr))
>           |                                          ^~~~~~~~~~~~~~~~
>     progs/verifier_bpf_fastcall.c:652:11: note: in expansion of macro ‘__imm_insn’
>       652 |           __imm_insn(may_goto, BPF_RAW_INSN(BPF_JMP | BPF_JCOND, 0, 0, +1 /* offset */, 0))
>           |           ^~~~~~~~~~
>     /ci/workspace/tools/testing/selftests/bpf/../../../include/linux/filter.h:299:28:
> note: ‘({anonymous})’ declared here
>       299 |         ((struct bpf_insn) {                                    \
>           |                            ^
>     progs/bpf_misc.h:153:53: note: in definition of macro ‘__imm_insn’
>       153 | #define __imm_insn(name, expr) [name]"i"(*(long *)&(expr))
>           |                                                     ^~~~
>     progs/verifier_bpf_fastcall.c:652:32: note: in expansion of macro ‘BPF_RAW_INSN’
>       652 |           __imm_insn(may_goto, BPF_RAW_INSN(BPF_JMP | BPF_JCOND, 0, 0, +1 /* offset */, 0))
>
> BPF_RAW_INSN expands into struct init expr (include/linux/filter.h):
>
>     #define BPF_RAW_INSN(CODE, DST, SRC, OFF, IMM)			\
>     	((struct bpf_insn) {					\
>     		.code  = CODE,					\
>     		.dst_reg = DST,					\
>     		.src_reg = SRC,					\
>     		.off   = OFF,					\
>     		.imm   = IMM })
>
> This can be silenced with:
>
> +progs/verifier_bpf_fastcall.c-CFLAGS := -Wno-error
> +progs/verifier_search_pruning.c-CFLAGS := -Wno-error

Ignoring the warning doesn't cure the resulting undefined behavior.
These selftests seems to be violating strict aliasing rules, so it is
better to either change the testcase to work well with anti-aliasing
rules or to disable strict aliasing, like it is done for many other
tests already:

progs/verifier_bpf_fastcall.c-CFLAGS := -fno-strict-aliasing
progs/verifier_search_pruning.c-CFLAGS := -fno-strict-aliasing

> Then the selftests/bpf build completes successfully, although libbpf
> prints a lot of warnings like these on GEN-SKEL:
>
>     [...]
>     libbpf: elf: skipping section(3) .data (size 0)
>     libbpf: elf: skipping section(4) .data (size 0)
>     libbpf: elf: skipping unrecognized data section(13) .comment
>     libbpf: elf: skipping unrecognized data section(9) .comment
>     libbpf: elf: skipping unrecognized data section(12) .comment
>     libbpf: elf: skipping unrecognized data section(7) .comment
>     [...]
>
> Test .bpf.o files are compiled regardless. Full log at [2].
>
> Running all tests at once, as is usually done on CI, produces a too
> cluttered log. I wrote a script to run each test individually in a
> separate qemu instance and collect the logs.
>
> 187/581 of toplevel tests fail on current bpf-next [3]. Many tests
> have subtests: toplevel test passes if all of its subtests pass.

Thanks for the report.

>
> You can find the archive with per-test logs at [4].
>
> [1] https://gist.github.com/theihor/10b2425e6780fcfebb80aeceafba7678
> [2] https://gist.github.com/theihor/9e96643ca730365cf79cea8445e40aeb
> [3] https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git/commit/?id=96ea081ed52bf077cad6d00153b6fba68e510767
> [4] https://github.com/kernel-patches/bpf/blob/8f2e62702ee17675464ab00d97d89d599922de20/tools/testing/selftests/bpf/gcc-bpf-selftests-logs.tgz





[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