summaryrefslogtreecommitdiff
path: root/tools/testing/selftests/bpf/progs/btf_ptr.h
diff options
context:
space:
mode:
authorAlan Maguire <alan.maguire@oracle.com>2020-09-29 14:32:31 +0300
committerAlexei Starovoitov <ast@kernel.org>2020-09-29 21:10:48 +0300
commitcfe77683b8d4c22d25e7cc40319f1dfe5401c48a (patch)
tree3f29be202a46a6602d3ff5c65a02ed9cbdb4d5b4 /tools/testing/selftests/bpf/progs/btf_ptr.h
parent96c48058db150639553fc4d7b89c236bf5c9257e (diff)
downloadlinux-cfe77683b8d4c22d25e7cc40319f1dfe5401c48a.tar.xz
selftests/bpf: Ensure snprintf_btf/bpf_iter tests compatibility with old vmlinux.h
Andrii reports that bpf selftests relying on "struct btf_ptr" and BTF_F_* values will not build as vmlinux.h for older kernels will not include "struct btf_ptr" or the BTF_F_* enum values. Undefine and redefine them to work around this. Fixes: b72091bd4ee4 ("selftests/bpf: Add test for bpf_seq_printf_btf helper") Fixes: 076a95f5aff2 ("selftests/bpf: Add bpf_snprintf_btf helper tests") Reported-by: Andrii Nakryiko <andrii.nakryiko@gmail.com> Signed-off-by: Alan Maguire <alan.maguire@oracle.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Acked-by: Andrii Nakryiko <andriin@fb.com> Link: https://lore.kernel.org/bpf/1601379151-21449-3-git-send-email-alan.maguire@oracle.com
Diffstat (limited to 'tools/testing/selftests/bpf/progs/btf_ptr.h')
-rw-r--r--tools/testing/selftests/bpf/progs/btf_ptr.h27
1 files changed, 27 insertions, 0 deletions
diff --git a/tools/testing/selftests/bpf/progs/btf_ptr.h b/tools/testing/selftests/bpf/progs/btf_ptr.h
new file mode 100644
index 000000000000..c3c9797c67db
--- /dev/null
+++ b/tools/testing/selftests/bpf/progs/btf_ptr.h
@@ -0,0 +1,27 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Copyright (c) 2020, Oracle and/or its affiliates. */
+/* "undefine" structs in vmlinux.h, because we "override" them below */
+#define btf_ptr btf_ptr___not_used
+#define BTF_F_COMPACT BTF_F_COMPACT___not_used
+#define BTF_F_NONAME BTF_F_NONAME___not_used
+#define BTF_F_PTR_RAW BTF_F_PTR_RAW___not_used
+#define BTF_F_ZERO BTF_F_ZERO___not_used
+#include "vmlinux.h"
+#undef btf_ptr
+#undef BTF_F_COMPACT
+#undef BTF_F_NONAME
+#undef BTF_F_PTR_RAW
+#undef BTF_F_ZERO
+
+struct btf_ptr {
+ void *ptr;
+ __u32 type_id;
+ __u32 flags;
+};
+
+enum {
+ BTF_F_COMPACT = (1ULL << 0),
+ BTF_F_NONAME = (1ULL << 1),
+ BTF_F_PTR_RAW = (1ULL << 2),
+ BTF_F_ZERO = (1ULL << 3),
+};