Add BPF_ANNOTATE_KV_PAIR to BPF map definition macros
BPF_ANNOTATE_KV_PAIR is used by libbpf to associate each map with its
BTF information. This is ignored for programs compiled without BTF
information.
Bug: 203823368
Test: build & boot; confirm all bpf progs load successfully
Test: compile time_in_state.o with -g; confirm BTF is loaded
Signed-off-by: Connor O'Brien <connoro@google.com>
Change-Id: I45f294945d48106d39d1d105ac4f49311459a19d
diff --git a/staticlibs/native/bpf_headers/include/bpf/bpf_helpers.h b/staticlibs/native/bpf_headers/include/bpf/bpf_helpers.h
index 878bb10..ac9f9bc 100644
--- a/staticlibs/native/bpf_headers/include/bpf/bpf_helpers.h
+++ b/staticlibs/native/bpf_headers/include/bpf/bpf_helpers.h
@@ -116,6 +116,15 @@
static int (*bpf_map_delete_elem_unsafe)(const struct bpf_map_def* map,
const void* key) = (void*)BPF_FUNC_map_delete_elem;
+#define BPF_ANNOTATE_KV_PAIR(name, type_key, type_val) \
+ struct ____btf_map_##name { \
+ type_key key; \
+ type_val value; \
+ }; \
+ struct ____btf_map_##name \
+ __attribute__ ((section(".maps." #name), used)) \
+ ____btf_map_##name = { }
+
/* type safe macro to declare a map and related accessor functions */
#define DEFINE_BPF_MAP_UGM(the_map, TYPE, TypeOfKey, TypeOfValue, num_entries, usr, grp, md) \
const struct bpf_map_def SECTION("maps") the_map = { \
@@ -132,6 +141,7 @@
.min_kver = KVER_NONE, \
.max_kver = KVER_INF, \
}; \
+ BPF_ANNOTATE_KV_PAIR(the_map, TypeOfKey, TypeOfValue); \
\
static inline __always_inline __unused TypeOfValue* bpf_##the_map##_lookup_elem( \
const TypeOfKey* k) { \