Lines Matching refs:btf

25 struct btf {  struct
44 static int btf_add_type(struct btf *btf, struct btf_type *t) in btf_add_type() argument
46 if (btf->types_size - btf->nr_types < 2) { in btf_add_type()
50 if (btf->types_size == BTF_MAX_NR_TYPES) in btf_add_type()
53 expand_by = max(btf->types_size >> 2, 16); in btf_add_type()
54 new_size = min(BTF_MAX_NR_TYPES, btf->types_size + expand_by); in btf_add_type()
56 new_types = realloc(btf->types, sizeof(*new_types) * new_size); in btf_add_type()
60 if (btf->nr_types == 0) in btf_add_type()
63 btf->types = new_types; in btf_add_type()
64 btf->types_size = new_size; in btf_add_type()
67 btf->types[++(btf->nr_types)] = t; in btf_add_type()
72 static int btf_parse_hdr(struct btf *btf) in btf_parse_hdr() argument
74 const struct btf_header *hdr = btf->hdr; in btf_parse_hdr()
77 if (btf->data_size < sizeof(struct btf_header)) { in btf_parse_hdr()
97 meta_left = btf->data_size - sizeof(*hdr); in btf_parse_hdr()
123 btf->nohdr_data = btf->hdr + 1; in btf_parse_hdr()
128 static int btf_parse_str_sec(struct btf *btf) in btf_parse_str_sec() argument
130 const struct btf_header *hdr = btf->hdr; in btf_parse_str_sec()
131 const char *start = btf->nohdr_data + hdr->str_off; in btf_parse_str_sec()
132 const char *end = start + btf->hdr->str_len; in btf_parse_str_sec()
140 btf->strings = start; in btf_parse_str_sec()
180 static int btf_parse_type_sec(struct btf *btf) in btf_parse_type_sec() argument
182 struct btf_header *hdr = btf->hdr; in btf_parse_type_sec()
183 void *nohdr_data = btf->nohdr_data; in btf_parse_type_sec()
196 err = btf_add_type(btf, t); in btf_parse_type_sec()
204 __u32 btf__get_nr_types(const struct btf *btf) in btf__get_nr_types() argument
206 return btf->nr_types; in btf__get_nr_types()
209 const struct btf_type *btf__type_by_id(const struct btf *btf, __u32 type_id) in btf__type_by_id() argument
211 if (type_id > btf->nr_types) in btf__type_by_id()
214 return btf->types[type_id]; in btf__type_by_id()
229 __s64 btf__resolve_size(const struct btf *btf, __u32 type_id) in btf__resolve_size() argument
237 t = btf__type_by_id(btf, type_id); in btf__resolve_size()
269 t = btf__type_by_id(btf, type_id); in btf__resolve_size()
282 int btf__resolve_type(const struct btf *btf, __u32 type_id) in btf__resolve_type() argument
287 t = btf__type_by_id(btf, type_id); in btf__resolve_type()
292 t = btf__type_by_id(btf, type_id); in btf__resolve_type()
302 __s32 btf__find_by_name(const struct btf *btf, const char *type_name) in btf__find_by_name() argument
309 for (i = 1; i <= btf->nr_types; i++) { in btf__find_by_name()
310 const struct btf_type *t = btf->types[i]; in btf__find_by_name()
311 const char *name = btf__name_by_offset(btf, t->name_off); in btf__find_by_name()
320 void btf__free(struct btf *btf) in btf__free() argument
322 if (!btf) in btf__free()
325 if (btf->fd != -1) in btf__free()
326 close(btf->fd); in btf__free()
328 free(btf->data); in btf__free()
329 free(btf->types); in btf__free()
330 free(btf); in btf__free()
333 struct btf *btf__new(__u8 *data, __u32 size) in btf__new()
335 struct btf *btf; in btf__new() local
338 btf = calloc(1, sizeof(struct btf)); in btf__new()
339 if (!btf) in btf__new()
342 btf->fd = -1; in btf__new()
344 btf->data = malloc(size); in btf__new()
345 if (!btf->data) { in btf__new()
350 memcpy(btf->data, data, size); in btf__new()
351 btf->data_size = size; in btf__new()
353 err = btf_parse_hdr(btf); in btf__new()
357 err = btf_parse_str_sec(btf); in btf__new()
361 err = btf_parse_type_sec(btf); in btf__new()
365 btf__free(btf); in btf__new()
369 return btf; in btf__new()
383 struct btf *btf__parse_elf(const char *path, struct btf_ext **btf_ext) in btf__parse_elf()
387 struct btf *btf = NULL; in btf__parse_elf() local
465 btf = btf__new(btf_data->d_buf, btf_data->d_size); in btf__parse_elf()
466 if (IS_ERR(btf)) in btf__parse_elf()
488 if (IS_ERR(btf)) in btf__parse_elf()
489 return btf; in btf__parse_elf()
491 btf__free(btf); in btf__parse_elf()
495 return btf; in btf__parse_elf()
506 static int btf_fixup_datasec(struct bpf_object *obj, struct btf *btf, in btf_fixup_datasec() argument
510 const char *name = btf__name_by_offset(btf, t->name_off); in btf_fixup_datasec()
530 t_var = btf__type_by_id(btf, vsi->type); in btf_fixup_datasec()
541 name = btf__name_by_offset(btf, t_var->name_off); in btf_fixup_datasec()
561 int btf__finalize_data(struct bpf_object *obj, struct btf *btf) in btf__finalize_data() argument
566 for (i = 1; i <= btf->nr_types; i++) { in btf__finalize_data()
567 struct btf_type *t = btf->types[i]; in btf__finalize_data()
575 err = btf_fixup_datasec(obj, btf, t); in btf__finalize_data()
584 int btf__load(struct btf *btf) in btf__load() argument
590 if (btf->fd >= 0) in btf__load()
599 btf->fd = bpf_load_btf(btf->data, btf->data_size, in btf__load()
601 if (btf->fd < 0) { in btf__load()
614 int btf__fd(const struct btf *btf) in btf__fd() argument
616 return btf->fd; in btf__fd()
619 const void *btf__get_raw_data(const struct btf *btf, __u32 *size) in btf__get_raw_data() argument
621 *size = btf->data_size; in btf__get_raw_data()
622 return btf->data; in btf__get_raw_data()
625 const char *btf__name_by_offset(const struct btf *btf, __u32 offset) in btf__name_by_offset() argument
627 if (offset < btf->hdr->str_len) in btf__name_by_offset()
628 return &btf->strings[offset]; in btf__name_by_offset()
633 int btf__get_from_id(__u32 id, struct btf **btf) in btf__get_from_id() argument
643 *btf = NULL; in btf__get_from_id()
661 btf_info.btf = ptr_to_u64(ptr); in btf__get_from_id()
675 btf_info.btf = ptr_to_u64(ptr); in btf__get_from_id()
684 *btf = btf__new((__u8 *)(long)btf_info.btf, btf_info.btf_size); in btf__get_from_id()
685 if (IS_ERR(*btf)) { in btf__get_from_id()
686 err = PTR_ERR(*btf); in btf__get_from_id()
687 *btf = NULL; in btf__get_from_id()
697 int btf__get_map_kv_tids(const struct btf *btf, const char *map_name, in btf__get_map_kv_tids() argument
715 container_id = btf__find_by_name(btf, container_name); in btf__get_map_kv_tids()
722 container_type = btf__type_by_id(btf, container_id); in btf__get_map_kv_tids()
738 key_size = btf__resolve_size(btf, key->type); in btf__get_map_kv_tids()
750 value_size = btf__resolve_size(btf, value->type); in btf__get_map_kv_tids()
999 static int btf_ext_reloc_info(const struct btf *btf, in btf_ext_reloc_info() argument
1016 info_sec_name = btf__name_by_offset(btf, sinfo->sec_name_off); in btf_ext_reloc_info()
1047 int btf_ext__reloc_func_info(const struct btf *btf, in btf_ext__reloc_func_info() argument
1052 return btf_ext_reloc_info(btf, &btf_ext->func_info, sec_name, in btf_ext__reloc_func_info()
1056 int btf_ext__reloc_line_info(const struct btf *btf, in btf_ext__reloc_line_info() argument
1061 return btf_ext_reloc_info(btf, &btf_ext->line_info, sec_name, in btf_ext__reloc_line_info()
1077 static struct btf_dedup *btf_dedup_new(struct btf *btf, struct btf_ext *btf_ext,
1224 int btf__dedup(struct btf *btf, struct btf_ext *btf_ext, in btf__dedup() argument
1227 struct btf_dedup *d = btf_dedup_new(btf, btf_ext, opts); in btf__dedup()
1276 struct btf *btf; member
1386 static struct btf_dedup *btf_dedup_new(struct btf *btf, struct btf_ext *btf_ext, in btf_dedup_new() argument
1401 d->btf = btf; in btf_dedup_new()
1411 d->map = malloc(sizeof(__u32) * (1 + btf->nr_types)); in btf_dedup_new()
1418 for (i = 1; i <= btf->nr_types; i++) { in btf_dedup_new()
1419 struct btf_type *t = d->btf->types[i]; in btf_dedup_new()
1428 d->hypot_map = malloc(sizeof(__u32) * (1 + btf->nr_types)); in btf_dedup_new()
1433 for (i = 0; i <= btf->nr_types; i++) in btf_dedup_new()
1457 for (i = 1; i <= d->btf->nr_types; i++) { in btf_for_each_str_off()
1458 t = d->btf->types[i]; in btf_for_each_str_off()
1612 const struct btf_header *hdr = d->btf->hdr; in btf_dedup_strings()
1613 char *start = (char *)d->btf->nohdr_data + hdr->str_off; in btf_dedup_strings()
1614 char *end = start + d->btf->hdr->str_len; in btf_dedup_strings()
1648 tmp_strs = malloc(d->btf->hdr->str_len); in btf_dedup_strings()
1705 d->btf->hdr->str_len = p - tmp_strs; in btf_dedup_strings()
1706 memmove(start, tmp_strs, d->btf->hdr->str_len); in btf_dedup_strings()
1707 end = start + d->btf->hdr->str_len; in btf_dedup_strings()
1717 d->btf->hdr->str_len = end - start; in btf_dedup_strings()
1994 struct btf_type *t = d->btf->types[type_id]; in btf_dedup_prim_type()
2021 cand = d->btf->types[cand_id]; in btf_dedup_prim_type()
2033 cand = d->btf->types[cand_id]; in btf_dedup_prim_type()
2056 cand = d->btf->types[cand_id]; in btf_dedup_prim_type()
2079 for (i = 1; i <= d->btf->nr_types; i++) { in btf_dedup_prim_types()
2115 if (!btf_is_fwd(d->btf->types[type_id])) in resolve_fwd_id()
2121 if (!btf_is_fwd(d->btf->types[type_id])) in resolve_fwd_id()
2249 cand_type = d->btf->types[cand_id]; in btf_dedup_is_equiv()
2250 canon_type = d->btf->types[canon_id]; in btf_dedup_is_equiv()
2401 t_kind = btf_kind(d->btf->types[t_id]); in btf_dedup_merge_hypot_map()
2402 c_kind = btf_kind(d->btf->types[c_id]); in btf_dedup_merge_hypot_map()
2470 t = d->btf->types[type_id]; in btf_dedup_struct_type()
2491 cand_type = d->btf->types[cand_id]; in btf_dedup_struct_type()
2517 for (i = 1; i <= d->btf->nr_types; i++) { in btf_dedup_struct_types()
2563 t = d->btf->types[type_id]; in btf_dedup_ref_type()
2581 cand = d->btf->types[cand_id]; in btf_dedup_ref_type()
2605 cand = d->btf->types[cand_id]; in btf_dedup_ref_type()
2637 cand = d->btf->types[cand_id]; in btf_dedup_ref_type()
2661 for (i = 1; i <= d->btf->nr_types; i++) { in btf_dedup_ref_types()
2692 for (i = 1; i <= d->btf->nr_types; i++) in btf_dedup_compact_types()
2695 types_start = d->btf->nohdr_data + d->btf->hdr->type_off; in btf_dedup_compact_types()
2698 for (i = 1; i <= d->btf->nr_types; i++) { in btf_dedup_compact_types()
2702 len = btf_type_size(d->btf->types[i]); in btf_dedup_compact_types()
2706 memmove(p, d->btf->types[i], len); in btf_dedup_compact_types()
2708 d->btf->types[next_type_id] = (struct btf_type *)p; in btf_dedup_compact_types()
2714 d->btf->nr_types = next_type_id - 1; in btf_dedup_compact_types()
2715 d->btf->types_size = d->btf->nr_types; in btf_dedup_compact_types()
2716 d->btf->hdr->type_len = p - types_start; in btf_dedup_compact_types()
2717 new_types = realloc(d->btf->types, in btf_dedup_compact_types()
2718 (1 + d->btf->nr_types) * sizeof(struct btf_type *)); in btf_dedup_compact_types()
2721 d->btf->types = new_types; in btf_dedup_compact_types()
2724 d->btf->hdr->str_off = p - (char *)d->btf->nohdr_data; in btf_dedup_compact_types()
2725 memmove(p, d->btf->strings, d->btf->hdr->str_len); in btf_dedup_compact_types()
2726 d->btf->strings = p; in btf_dedup_compact_types()
2727 p += d->btf->hdr->str_len; in btf_dedup_compact_types()
2729 d->btf->data_size = p - (char *)d->btf->data; in btf_dedup_compact_types()
2762 struct btf_type *t = d->btf->types[type_id]; in btf_dedup_remap_type()
2857 for (i = 1; i <= d->btf->nr_types; i++) { in btf_dedup_remap_types()