Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1/* SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) */
2/* Copyright (c) 2018 Facebook */
3
4#ifndef __LIBBPF_BTF_H
5#define __LIBBPF_BTF_H
6
7#include <linux/types.h>
8
9#ifdef __cplusplus
10extern "C" {
11#endif
12
13#ifndef LIBBPF_API
14#define LIBBPF_API __attribute__((visibility("default")))
15#endif
16
17#define BTF_ELF_SEC ".BTF"
18#define BTF_EXT_ELF_SEC ".BTF.ext"
19
20struct btf;
21struct btf_ext;
22struct btf_type;
23
24struct bpf_object;
25
26/*
27 * The .BTF.ext ELF section layout defined as
28 * struct btf_ext_header
29 * func_info subsection
30 *
31 * The func_info subsection layout:
32 * record size for struct bpf_func_info in the func_info subsection
33 * struct btf_sec_func_info for section #1
34 * a list of bpf_func_info records for section #1
35 * where struct bpf_func_info mimics one in include/uapi/linux/bpf.h
36 * but may not be identical
37 * struct btf_sec_func_info for section #2
38 * a list of bpf_func_info records for section #2
39 * ......
40 *
41 * Note that the bpf_func_info record size in .BTF.ext may not
42 * be the same as the one defined in include/uapi/linux/bpf.h.
43 * The loader should ensure that record_size meets minimum
44 * requirement and pass the record as is to the kernel. The
45 * kernel will handle the func_info properly based on its contents.
46 */
47struct btf_ext_header {
48 __u16 magic;
49 __u8 version;
50 __u8 flags;
51 __u32 hdr_len;
52
53 /* All offsets are in bytes relative to the end of this header */
54 __u32 func_info_off;
55 __u32 func_info_len;
56 __u32 line_info_off;
57 __u32 line_info_len;
58};
59
60LIBBPF_API void btf__free(struct btf *btf);
61LIBBPF_API struct btf *btf__new(__u8 *data, __u32 size);
62LIBBPF_API int btf__finalize_data(struct bpf_object *obj, struct btf *btf);
63LIBBPF_API int btf__load(struct btf *btf);
64LIBBPF_API __s32 btf__find_by_name(const struct btf *btf,
65 const char *type_name);
66LIBBPF_API __u32 btf__get_nr_types(const struct btf *btf);
67LIBBPF_API const struct btf_type *btf__type_by_id(const struct btf *btf,
68 __u32 id);
69LIBBPF_API __s64 btf__resolve_size(const struct btf *btf, __u32 type_id);
70LIBBPF_API int btf__resolve_type(const struct btf *btf, __u32 type_id);
71LIBBPF_API int btf__fd(const struct btf *btf);
72LIBBPF_API const void *btf__get_raw_data(const struct btf *btf, __u32 *size);
73LIBBPF_API const char *btf__name_by_offset(const struct btf *btf, __u32 offset);
74LIBBPF_API int btf__get_from_id(__u32 id, struct btf **btf);
75LIBBPF_API int btf__get_map_kv_tids(const struct btf *btf, const char *map_name,
76 __u32 expected_key_size,
77 __u32 expected_value_size,
78 __u32 *key_type_id, __u32 *value_type_id);
79
80LIBBPF_API struct btf_ext *btf_ext__new(__u8 *data, __u32 size);
81LIBBPF_API void btf_ext__free(struct btf_ext *btf_ext);
82LIBBPF_API const void *btf_ext__get_raw_data(const struct btf_ext *btf_ext,
83 __u32 *size);
84LIBBPF_API int btf_ext__reloc_func_info(const struct btf *btf,
85 const struct btf_ext *btf_ext,
86 const char *sec_name, __u32 insns_cnt,
87 void **func_info, __u32 *cnt);
88LIBBPF_API int btf_ext__reloc_line_info(const struct btf *btf,
89 const struct btf_ext *btf_ext,
90 const char *sec_name, __u32 insns_cnt,
91 void **line_info, __u32 *cnt);
92LIBBPF_API __u32 btf_ext__func_info_rec_size(const struct btf_ext *btf_ext);
93LIBBPF_API __u32 btf_ext__line_info_rec_size(const struct btf_ext *btf_ext);
94
95struct btf_dedup_opts {
96 unsigned int dedup_table_size;
97 bool dont_resolve_fwds;
98};
99
100LIBBPF_API int btf__dedup(struct btf *btf, struct btf_ext *btf_ext,
101 const struct btf_dedup_opts *opts);
102
103#ifdef __cplusplus
104} /* extern "C" */
105#endif
106
107#endif /* __LIBBPF_BTF_H */