selftests/bpf: Define string const as global for test_sysctl_prog.c
authorYonghong Song <yhs@fb.com>
Thu, 10 Sep 2020 20:27:18 +0000 (13:27 -0700)
committerAlexei Starovoitov <ast@kernel.org>
Fri, 11 Sep 2020 03:01:53 +0000 (20:01 -0700)
commit6e057fc15a2da4ee03eb1fa6889cf687e690106e
treebf5be5b534483aea4fcbe8b7a7df9627d9d912c1
parent90a1deda75c6b749fb89310e4744554a4c36ea33
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 7fb5eefd7639 ("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 <yhs@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Andrii Nakryiko <andriin@fb.com>
Link: https://lore.kernel.org/bpf/20200910202718.956042-1-yhs@fb.com
tools/testing/selftests/bpf/progs/test_sysctl_prog.c