1 /* SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) */
2 /* Copyright (c) 2018 Facebook */
7 #include <linux/types.h>
14 #define LIBBPF_API __attribute__((visibility("default")))
17 #define BTF_ELF_SEC ".BTF"
18 #define BTF_EXT_ELF_SEC ".BTF.ext"
25 * The .BTF.ext ELF section layout defined as
26 * struct btf_ext_header
27 * func_info subsection
29 * The func_info subsection layout:
30 * record size for struct bpf_func_info in the func_info subsection
31 * struct btf_sec_func_info for section #1
32 * a list of bpf_func_info records for section #1
33 * where struct bpf_func_info mimics one in include/uapi/linux/bpf.h
34 * but may not be identical
35 * struct btf_sec_func_info for section #2
36 * a list of bpf_func_info records for section #2
39 * Note that the bpf_func_info record size in .BTF.ext may not
40 * be the same as the one defined in include/uapi/linux/bpf.h.
41 * The loader should ensure that record_size meets minimum
42 * requirement and pass the record as is to the kernel. The
43 * kernel will handle the func_info properly based on its contents.
45 struct btf_ext_header {
51 /* All offsets are in bytes relative to the end of this header */
58 LIBBPF_API void btf__free(struct btf *btf);
59 LIBBPF_API struct btf *btf__new(__u8 *data, __u32 size);
60 LIBBPF_API int btf__load(struct btf *btf);
61 LIBBPF_API __s32 btf__find_by_name(const struct btf *btf,
62 const char *type_name);
63 LIBBPF_API __u32 btf__get_nr_types(const struct btf *btf);
64 LIBBPF_API const struct btf_type *btf__type_by_id(const struct btf *btf,
66 LIBBPF_API __s64 btf__resolve_size(const struct btf *btf, __u32 type_id);
67 LIBBPF_API int btf__resolve_type(const struct btf *btf, __u32 type_id);
68 LIBBPF_API int btf__fd(const struct btf *btf);
69 LIBBPF_API const void *btf__get_raw_data(const struct btf *btf, __u32 *size);
70 LIBBPF_API const char *btf__name_by_offset(const struct btf *btf, __u32 offset);
71 LIBBPF_API int btf__get_from_id(__u32 id, struct btf **btf);
72 LIBBPF_API int btf__get_map_kv_tids(const struct btf *btf, const char *map_name,
73 __u32 expected_key_size,
74 __u32 expected_value_size,
75 __u32 *key_type_id, __u32 *value_type_id);
77 LIBBPF_API struct btf_ext *btf_ext__new(__u8 *data, __u32 size);
78 LIBBPF_API void btf_ext__free(struct btf_ext *btf_ext);
79 LIBBPF_API const void *btf_ext__get_raw_data(const struct btf_ext *btf_ext,
81 LIBBPF_API int btf_ext__reloc_func_info(const struct btf *btf,
82 const struct btf_ext *btf_ext,
83 const char *sec_name, __u32 insns_cnt,
84 void **func_info, __u32 *cnt);
85 LIBBPF_API int btf_ext__reloc_line_info(const struct btf *btf,
86 const struct btf_ext *btf_ext,
87 const char *sec_name, __u32 insns_cnt,
88 void **line_info, __u32 *cnt);
89 LIBBPF_API __u32 btf_ext__func_info_rec_size(const struct btf_ext *btf_ext);
90 LIBBPF_API __u32 btf_ext__line_info_rec_size(const struct btf_ext *btf_ext);
92 struct btf_dedup_opts {
93 unsigned int dedup_table_size;
94 bool dont_resolve_fwds;
97 LIBBPF_API int btf__dedup(struct btf *btf, struct btf_ext *btf_ext,
98 const struct btf_dedup_opts *opts);
104 #endif /* __LIBBPF_BTF_H */