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

selftests/bpf: Workaround for llvm nop-4 bug

Currently LLVM fails to recognize .data.* as data section and defaults to .text
section. Later BPF backend tries to emit 4-byte NOP instruction which doesn't
exist in BPF ISA and aborts.
The fix for LLVM is pending:
https://reviews.llvm.org/D138477

While waiting for the fix lets workaround the linked_list test case
by using .bss.* prefix which is properly recognized by LLVM as BSS section.

Fix libbpf to support .bss. prefix and adjust tests.

Signed-off-by: Alexei Starovoitov <ast@kernel.org>

+6 -5
+2 -1
tools/lib/bpf/libbpf.c
··· 3511 3511 sec_desc->sec_type = SEC_RELO; 3512 3512 sec_desc->shdr = sh; 3513 3513 sec_desc->data = data; 3514 - } else if (sh->sh_type == SHT_NOBITS && strcmp(name, BSS_SEC) == 0) { 3514 + } else if (sh->sh_type == SHT_NOBITS && (strcmp(name, BSS_SEC) == 0 || 3515 + str_has_pfx(name, BSS_SEC "."))) { 3515 3516 sec_desc->sec_type = SEC_BSS; 3516 3517 sec_desc->shdr = sh; 3517 3518 sec_desc->data = data;
+3 -3
tools/testing/selftests/bpf/prog_tests/linked_list.c
··· 189 189 ASSERT_OK(ret, "global_list_push_pop"); 190 190 ASSERT_OK(opts.retval, "global_list_push_pop retval"); 191 191 if (!leave_in_map) 192 - clear_fields(skel->maps.data_A); 192 + clear_fields(skel->maps.bss_A); 193 193 194 194 if (mode == PUSH_POP) 195 195 goto end; ··· 211 211 ASSERT_OK(ret, "global_list_push_pop_multiple"); 212 212 ASSERT_OK(opts.retval, "global_list_push_pop_multiple retval"); 213 213 if (!leave_in_map) 214 - clear_fields(skel->maps.data_A); 214 + clear_fields(skel->maps.bss_A); 215 215 216 216 if (mode == PUSH_POP_MULT) 217 217 goto end; ··· 233 233 ASSERT_OK(ret, "global_list_in_list"); 234 234 ASSERT_OK(opts.retval, "global_list_in_list retval"); 235 235 if (!leave_in_map) 236 - clear_fields(skel->maps.data_A); 236 + clear_fields(skel->maps.bss_A); 237 237 end: 238 238 linked_list__destroy(skel); 239 239 }
+1 -1
tools/testing/selftests/bpf/progs/linked_list.h
··· 47 47 }, 48 48 }; 49 49 50 - #define private(name) SEC(".data." #name) __hidden __attribute__((aligned(8))) 50 + #define private(name) SEC(".bss." #name) __hidden __attribute__((aligned(8))) 51 51 52 52 private(A) struct bpf_spin_lock glock; 53 53 private(A) struct bpf_list_head ghead __contains(foo, node);