bpf: ignore expected GCC warning in test_global_func10.c
Subsystems (3)
PATCH 1/1 bpf: ignore expected GCC warning in test_global_func10.c
The BPF selftest global_func10 in progs/test_global_func10.c contains:
struct Small {
long x;
};
struct Big {
long x;
long y;
};[...]
__noinline int foo(const struct Big *big)
{
if (!big)
return 0;
return bpf_get_prandom_u32() < big->y;}
[...]
SEC("cgroup_skb/ingress")
__failure __msg("invalid indirect access to stack") int global_func10(struct __sk_buff *skb)
{
const struct Small small = {.x = skb->len };
return foo((struct Big *)&small) ? 1 : 0;}
GCC emits a "maybe uninitialized" warning for the code above, because it knows foo' accesses big->y'.
Since the purpose of this selftest is to check that the verifier will fail on this sort of invalid memory access, this patch just silences the compiler warning.
Tested in bpf-next master.
No regressions.
--- tools/testing/selftests/bpf/progs/test_global_func10.c | 4 ++++ 1 file changed, 4 insertions(+)
tools/testing/selftests/bpf/progs/test_global_func10.c +4 -0
@@ -4,6 +4,10 @@#include <bpf/bpf_helpers.h> #include "bpf_misc.h" +#if !defined(__clang__) +#pragma GCC diagnostic ignored "-Wmaybe-uninitialized" +#endif +struct Small {long x; };
Signature · 1 line
2.30.2
This patch was applied to bpf/bpf-next.git (master) by Alexei Starovoitov <[email protected]>:
Hello:
This patch was applied to bpf/bpf-next.git (master) by Alexei Starovoitov <[email protected]>:
Quoted 11 lines · On Sat, 11 May 2024 23:23:49 +0200 you wrote:
The BPF selftest
global_func10inprogs/test_global_func10.ccontains:struct Small { long x; }; struct Big { long x; long y; };
Quoted 1 line
[...]
Here is the summary with links:
- [bpf-next] bpf: ignore expected GCC warning in test_global_func10.c
https://git.kernel.org/bpf/bpf-next/c/6a2f786e6905
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html