Skip to content

Commit 6e057fc

Browse files
yonghong-songAlexei Starovoitov
authored andcommitted
selftests/bpf: Define string const as global for test_sysctl_prog.c
When tweaking llvm optimizations, I found that selftest build failed with the following error: libbpf: elf: skipping unrecognized data section(6) .rodata.str1.1 libbpf: prog 'sysctl_tcp_mem': bad map relo against '.L__const.is_tcp_mem.tcp_mem_name' in section '.rodata.str1.1' Error: failed to open BPF object file: Relocation failed make: *** [/work/net-next/tools/testing/selftests/bpf/test_sysctl_prog.skel.h] Error 255 make: *** Deleting file `/work/net-next/tools/testing/selftests/bpf/test_sysctl_prog.skel.h' The local string constant "tcp_mem_name" is put into '.rodata.str1.1' section which libbpf cannot handle. Using untweaked upstream llvm, "tcp_mem_name" is completely inlined after loop unrolling. Commit 7fb5eef ("selftests/bpf: Fix test_sysctl_loop{1, 2} failure due to clang change") solved a similar problem by defining the string const as a global. Let us do the same here for test_sysctl_prog.c so it can weather future potential llvm changes. Signed-off-by: Yonghong Song <[email protected]> Signed-off-by: Alexei Starovoitov <[email protected]> Acked-by: Andrii Nakryiko <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent 90a1ded commit 6e057fc

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

tools/testing/selftests/bpf/progs/test_sysctl_prog.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@
1919
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
2020
#endif
2121

22+
const char tcp_mem_name[] = "net/ipv4/tcp_mem";
2223
static __always_inline int is_tcp_mem(struct bpf_sysctl *ctx)
2324
{
24-
char tcp_mem_name[] = "net/ipv4/tcp_mem";
2525
unsigned char i;
26-
char name[64];
26+
char name[sizeof(tcp_mem_name)];
2727
int ret;
2828

2929
memset(name, 0, sizeof(name));

0 commit comments

Comments
 (0)