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

selftests/bpf: Make selftest compilation work on clang 11

We can't compile test_core_reloc_module.c selftest with clang 11, compile
fails with:

CLNG-LLC [test_maps] test_core_reloc_module.o
progs/test_core_reloc_module.c:57:21: error: use of unknown builtin \
'__builtin_preserve_type_info' [-Wimplicit-function-declaration]
out->read_ctx_sz = bpf_core_type_size(struct bpf_testmod_test_read_ctx);

Skipping these tests if __builtin_preserve_type_info() is not supported
by compiler.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20201209142912.99145-1-jolsa@kernel.org

authored by

Jiri Olsa and committed by
Daniel Borkmann
41003dd0 7535a352

+8
+8
tools/testing/selftests/bpf/progs/test_core_reloc_module.c
··· 40 40 struct task_struct *task, 41 41 struct bpf_testmod_test_read_ctx *read_ctx) 42 42 { 43 + #if __has_builtin(__builtin_preserve_enum_value) 43 44 struct core_reloc_module_output *out = (void *)&data.out; 44 45 __u64 pid_tgid = bpf_get_current_pid_tgid(); 45 46 __u32 real_tgid = (__u32)(pid_tgid >> 32); ··· 62 61 out->len_exists = bpf_core_field_exists(read_ctx->len); 63 62 64 63 out->comm_len = BPF_CORE_READ_STR_INTO(&out->comm, task, comm); 64 + #else 65 + data.skip = true; 66 + #endif 65 67 66 68 return 0; 67 69 } ··· 74 70 struct task_struct *task, 75 71 struct bpf_testmod_test_read_ctx *read_ctx) 76 72 { 73 + #if __has_builtin(__builtin_preserve_enum_value) 77 74 struct core_reloc_module_output *out = (void *)&data.out; 78 75 __u64 pid_tgid = bpf_get_current_pid_tgid(); 79 76 __u32 real_tgid = (__u32)(pid_tgid >> 32); ··· 96 91 out->len_exists = bpf_core_field_exists(read_ctx->len); 97 92 98 93 out->comm_len = BPF_CORE_READ_STR_INTO(&out->comm, task, comm); 94 + #else 95 + data.skip = true; 96 + #endif 99 97 100 98 return 0; 101 99 }