]> www.infradead.org Git - users/jedix/linux-maple.git/commit
selftests/bpf: add test for LDX/STX/ST relocations over array field
authorAndrii Nakryiko <andrii@kernel.org>
Fri, 7 Feb 2025 01:48:09 +0000 (17:48 -0800)
committerAlexei Starovoitov <ast@kernel.org>
Sat, 15 Feb 2025 03:58:14 +0000 (19:58 -0800)
commit4eb93fea59199c1aa6a6f837e90bdd597804cdcc
tree93087eca19676cf2e1ccdb32585694ef899e5a69
parent06096d19ee3897a7e70922580159607fe315da7a
selftests/bpf: add test for LDX/STX/ST relocations over array field

Add a simple repro for the issue of miscalculating LDX/STX/ST CO-RE
relocation size adjustment when the CO-RE relocation target type is an
ARRAY.

We need to make sure that compiler generates LDX/STX/ST instruction with
CO-RE relocation against entire ARRAY type, not ARRAY's element. With
the code pattern in selftest, we get this:

      59:       61 71 00 00 00 00 00 00 w1 = *(u32 *)(r7 + 0x0)
                00000000000001d8:  CO-RE <byte_off> [5] struct core_reloc_arrays::a (0:0)

Where offset of `int a[5]` is embedded (through CO-RE relocation) into memory
load instruction itself.

Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/r/20250207014809.1573841-2-andrii@kernel.org
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
tools/testing/selftests/bpf/prog_tests/core_reloc.c
tools/testing/selftests/bpf/progs/btf__core_reloc_arrays___err_bad_signed_arr_elem_sz.c [new file with mode: 0644]
tools/testing/selftests/bpf/progs/core_reloc_types.h
tools/testing/selftests/bpf/progs/test_core_reloc_arrays.c