Lines Matching refs:r
66 static int btf_relocate_rewrite_type_id(struct btf_relocate *r, __u32 i) in btf_relocate_rewrite_type_id() argument
68 struct btf_type *t = btf_type_by_id(r->btf, i); in btf_relocate_rewrite_type_id()
78 *id = r->id_map[*id]; in btf_relocate_rewrite_type_id()
132 static int btf_mark_embedded_composite_type_ids(struct btf_relocate *r, __u32 i) in btf_mark_embedded_composite_type_ids() argument
134 struct btf_type *t = btf_type_by_id(r->btf, i); in btf_mark_embedded_composite_type_ids()
150 t = btf_type_by_id(r->btf, next_id); in btf_mark_embedded_composite_type_ids()
167 if (next_id < r->nr_dist_base_types) in btf_mark_embedded_composite_type_ids()
168 r->id_map[next_id] = BTF_IS_EMBEDDED; in btf_mark_embedded_composite_type_ids()
184 static int btf_relocate_map_distilled_base(struct btf_relocate *r) in btf_relocate_map_distilled_base() argument
195 info = calloc(r->nr_dist_base_types, sizeof(*info)); in btf_relocate_map_distilled_base()
200 info_end = info + r->nr_dist_base_types; in btf_relocate_map_distilled_base()
201 for (id = 0; id < r->nr_dist_base_types; id++) { in btf_relocate_map_distilled_base()
202 dist_t = btf_type_by_id(r->dist_base_btf, id); in btf_relocate_map_distilled_base()
203 info[id].name = btf__name_by_offset(r->dist_base_btf, dist_t->name_off); in btf_relocate_map_distilled_base()
208 qsort(info, r->nr_dist_base_types, sizeof(*info), cmp_btf_name_size); in btf_relocate_map_distilled_base()
215 for (id = r->nr_dist_base_types; id < r->nr_dist_base_types + r->nr_split_types; id++) { in btf_relocate_map_distilled_base()
216 err = btf_mark_embedded_composite_type_ids(r, id); in btf_relocate_map_distilled_base()
225 base_name_cnt = calloc(r->base_str_len, sizeof(*base_name_cnt)); in btf_relocate_map_distilled_base()
230 for (id = 1; id < r->nr_base_types; id++) { in btf_relocate_map_distilled_base()
231 base_t = btf_type_by_id(r->base_btf, id); in btf_relocate_map_distilled_base()
239 for (id = 1; id < r->nr_base_types; id++) { in btf_relocate_map_distilled_base()
243 base_t = btf_type_by_id(r->base_btf, id); in btf_relocate_map_distilled_base()
249 base_info.name = btf__name_by_offset(r->base_btf, base_t->name_off); in btf_relocate_map_distilled_base()
278 for (dist_info = search_btf_name_size(&base_info, info, r->nr_dist_base_types); in btf_relocate_map_distilled_base()
282 if (!dist_info->id || dist_info->id >= r->nr_dist_base_types) { in btf_relocate_map_distilled_base()
288 dist_t = btf_type_by_id(r->dist_base_btf, dist_info->id); in btf_relocate_map_distilled_base()
335 if (r->id_map[dist_info->id] == BTF_IS_EMBEDDED && in btf_relocate_map_distilled_base()
342 if (r->id_map[dist_info->id] && in btf_relocate_map_distilled_base()
343 r->id_map[dist_info->id] != BTF_IS_EMBEDDED) { in btf_relocate_map_distilled_base()
354 base_t->size, id, r->id_map[dist_info->id]); in btf_relocate_map_distilled_base()
359 r->id_map[dist_info->id] = id; in btf_relocate_map_distilled_base()
360 r->str_map[dist_t->name_off] = base_t->name_off; in btf_relocate_map_distilled_base()
364 for (id = 1; id < r->nr_dist_base_types; id++) { in btf_relocate_map_distilled_base()
367 if (r->id_map[id] && r->id_map[id] != BTF_IS_EMBEDDED) in btf_relocate_map_distilled_base()
369 dist_t = btf_type_by_id(r->dist_base_btf, id); in btf_relocate_map_distilled_base()
370 name = btf__name_by_offset(r->dist_base_btf, dist_t->name_off); in btf_relocate_map_distilled_base()
383 static int btf_relocate_validate_distilled_base(struct btf_relocate *r) in btf_relocate_validate_distilled_base() argument
387 for (i = 1; i < r->nr_dist_base_types; i++) { in btf_relocate_validate_distilled_base()
388 struct btf_type *t = btf_type_by_id(r->dist_base_btf, i); in btf_relocate_validate_distilled_base()
412 static int btf_relocate_rewrite_strs(struct btf_relocate *r, __u32 i) in btf_relocate_rewrite_strs() argument
414 struct btf_type *t = btf_type_by_id(r->btf, i); in btf_relocate_rewrite_strs()
426 if (*str_off >= r->dist_str_len) { in btf_relocate_rewrite_strs()
427 *str_off += r->base_str_len - r->dist_str_len; in btf_relocate_rewrite_strs()
429 off = r->str_map[*str_off]; in btf_relocate_rewrite_strs()
432 btf__str_by_offset(r->btf, off), *str_off); in btf_relocate_rewrite_strs()
449 struct btf_relocate r = {}; in btf_relocate() local
453 r.dist_base_btf = btf__base_btf(btf); in btf_relocate()
454 if (!base_btf || r.dist_base_btf == base_btf) in btf_relocate()
457 r.nr_dist_base_types = btf__type_cnt(r.dist_base_btf); in btf_relocate()
458 r.nr_base_types = btf__type_cnt(base_btf); in btf_relocate()
459 r.nr_split_types = nr_types - r.nr_dist_base_types; in btf_relocate()
460 r.btf = btf; in btf_relocate()
461 r.base_btf = base_btf; in btf_relocate()
463 r.id_map = calloc(nr_types, sizeof(*r.id_map)); in btf_relocate()
464 r.str_map = calloc(btf_header(r.dist_base_btf)->str_len, sizeof(*r.str_map)); in btf_relocate()
465 dist_base_hdr = btf_header(r.dist_base_btf); in btf_relocate()
466 base_hdr = btf_header(r.base_btf); in btf_relocate()
467 r.dist_str_len = dist_base_hdr->str_len; in btf_relocate()
468 r.base_str_len = base_hdr->str_len; in btf_relocate()
469 if (!r.id_map || !r.str_map) { in btf_relocate()
474 err = btf_relocate_validate_distilled_base(&r); in btf_relocate()
482 for (id = r.nr_dist_base_types; id < nr_types; id++) in btf_relocate()
483 r.id_map[id] = id + r.nr_base_types - r.nr_dist_base_types; in btf_relocate()
489 err = btf_relocate_map_distilled_base(&r); in btf_relocate()
497 for (i = 0, id = r.nr_dist_base_types; i < r.nr_split_types; i++, id++) { in btf_relocate()
498 err = btf_relocate_rewrite_type_id(&r, id); in btf_relocate()
503 for (i = 0; i < r.nr_split_types; i++) { in btf_relocate()
504 err = btf_relocate_rewrite_strs(&r, i + r.nr_dist_base_types); in btf_relocate()
512 *id_map = r.id_map; in btf_relocate()
513 r.id_map = NULL; in btf_relocate()
516 free(r.id_map); in btf_relocate()
517 free(r.str_map); in btf_relocate()