Skip to content

Commit 00b2e95

Browse files
anakryikoAlexei Starovoitov
authored andcommitted
selftests/bpf: Add test validating failure on ambiguous relocation value
Add test simulating ambiguous field size relocation, while fields themselves are at the exact same offset. Signed-off-by: Andrii Nakryiko <[email protected]> Signed-off-by: Alexei Starovoitov <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent 353c788 commit 00b2e95

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

tools/testing/selftests/bpf/prog_tests/core_reloc.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,7 @@ static struct core_reloc_test_case test_cases[] = {
452452
/* size relocation checks */
453453
SIZE_CASE(size),
454454
SIZE_CASE(size___diff_sz),
455+
SIZE_ERR_CASE(size___err_ambiguous),
455456
};
456457

457458
struct data {
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#include "core_reloc_types.h"
2+
3+
void f(struct core_reloc_size___err_ambiguous1 x,
4+
struct core_reloc_size___err_ambiguous2 y) {}

tools/testing/selftests/bpf/progs/core_reloc_types.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -809,3 +809,28 @@ struct core_reloc_size___diff_sz {
809809
void *ptr_field;
810810
enum { OTHER_VALUE = 0xFFFFFFFFFFFFFFFF } enum_field;
811811
};
812+
813+
/* Error case of two candidates with the fields (int_field) at the same
814+
* offset, but with differing final relocation values: size 4 vs size 1
815+
*/
816+
struct core_reloc_size___err_ambiguous1 {
817+
/* int at offset 0 */
818+
int int_field;
819+
820+
struct { int x; } struct_field;
821+
union { int x; } union_field;
822+
int arr_field[4];
823+
void *ptr_field;
824+
enum { VALUE___1 = 123 } enum_field;
825+
};
826+
827+
struct core_reloc_size___err_ambiguous2 {
828+
/* char at offset 0 */
829+
char int_field;
830+
831+
struct { int x; } struct_field;
832+
union { int x; } union_field;
833+
int arr_field[4];
834+
void *ptr_field;
835+
enum { VALUE___2 = 123 } enum_field;
836+
};

0 commit comments

Comments
 (0)