Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests: net: declare section names for bpf_offload

Non-ancient ip (iproute2-5.15.0, libbpf 0.7.0) refuses to load
the sample with maps because we don't generate BTF:

libbpf: BTF is required, but is missing or corrupted.
ERROR: opening BPF object file failed

Enable BTF by adding -g to clang flags. With that done
neither of the programs load:

libbpf: prog 'func': error relocating .BTF.ext function info: -22
libbpf: prog 'func': failed to relocate calls: -22
libbpf: failed to load object 'ksft-net-drv/net/sample_ret0.bpf.o'

Andrii explains that this is because we don't specify
section names for the code. Add the section names, too.

Acked-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Stanislav Fomichev <sdf@google.com>
Acked-by: Martin KaFai Lau <martin.lau@kernel.org>
Link: https://lore.kernel.org/r/20240409031549.3531084-4-kuba@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

+7 -3
+2 -1
tools/testing/selftests/net/Makefile
··· 149 149 $(OUTPUT)/sample_map_ret0.bpf.o $(OUTPUT)/sample_ret0.bpf.o 150 150 151 151 $(BPF_PROG_OBJS): $(OUTPUT)/%.o : %.c $(BPFOBJ) | $(MAKE_DIRS) 152 - $(CLANG) -O2 --target=bpf -c $< $(CCINCLUDE) $(CLANG_SYS_INCLUDES) -o $@ 152 + $(CLANG) -O2 -g --target=bpf $(CCINCLUDE) $(CLANG_SYS_INCLUDES) \ 153 + -c $< -o $@ 153 154 154 155 $(BPFOBJ): $(wildcard $(BPFDIR)/*.[ch] $(BPFDIR)/Makefile) \ 155 156 $(APIDIR)/linux/bpf.h \
+1 -1
tools/testing/selftests/net/bpf_offload.py
··· 237 237 def ethtool(dev, opt, args, fail=True): 238 238 return cmd("ethtool %s %s %s" % (opt, dev["ifname"], args), fail=fail) 239 239 240 - def bpf_obj(name, sec=".text", path=bpf_test_dir,): 240 + def bpf_obj(name, sec="xdp", path=bpf_test_dir,): 241 241 return "obj %s sec %s" % (os.path.join(path, name), sec) 242 242 243 243 def bpf_pinned(name):
+1 -1
tools/testing/selftests/net/sample_map_ret0.bpf.c
··· 17 17 } array SEC(".maps"); 18 18 19 19 /* Sample program which should always load for testing control paths. */ 20 - SEC(".text") int func() 20 + SEC("xdp") int func() 21 21 { 22 22 __u64 key64 = 0; 23 23 __u32 key = 0;
+3
tools/testing/selftests/net/sample_ret0.bpf.c
··· 1 1 /* SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) */ 2 2 3 + #define SEC(name) __attribute__((section(name), used)) 4 + 3 5 /* Sample program which should always load for testing control paths. */ 6 + SEC("xdp") 4 7 int func() 5 8 { 6 9 return 0;