Lines Matching +full:num +full:- +full:ids

1 // SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
25 #define qsort(base, num, sz, cmp) sort(base, num, sz, cmp, NULL) argument
55 #define BTF_IS_EMBEDDED ((__u32)-1)
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()
83 * types are named. If strings match, and size is non-zero for both elements
90 int name_diff = strcmp(ni1->name, ni2->name); in cmp_btf_name_size()
92 if (!name_diff && ni1->needs_size && ni2->needs_size) in cmp_btf_name_size()
93 return ni2->size - ni1->size; in cmp_btf_name_size()
107 int high = nelems - 1; in search_btf_name_size()
119 high = mid - 1; in search_btf_name_size()
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()
157 next_id = t->type; in btf_mark_embedded_composite_type_ids()
162 next_id = a->type; 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()
181 /* Build a map from distilled base BTF ids to base BTF ids. To do so, iterate
192 /* generate a sort index array of name/type ids sorted by name for in btf_relocate_map_distilled_base()
193 * distilled base BTF to speed name-based lookups. in btf_relocate_map_distilled_base()
195 info = calloc(r->nr_dist_base_types, sizeof(*info)); in btf_relocate_map_distilled_base()
197 err = -ENOMEM; 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()
205 info[id].size = dist_t->size; 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_split_types; 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()
227 err = -ENOMEM; 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()
232 if (!btf_is_composite(base_t) || !base_t->name_off) in btf_relocate_map_distilled_base()
234 if (base_name_cnt[base_t->name_off] < 255) in btf_relocate_map_distilled_base()
235 base_name_cnt[base_t->name_off]++; 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()
245 if (!base_t->name_off) 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()
257 base_info.size = base_t->size; in btf_relocate_map_distilled_base()
271 base_info.needs_size = base_name_cnt[base_t->name_off] > 1; in btf_relocate_map_distilled_base()
272 base_info.size = base_t->size; 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()
284 id, dist_info->id); in btf_relocate_map_distilled_base()
285 err = -EINVAL; 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()
293 * occur for an identically-named type. in btf_relocate_map_distilled_base()
335 if (r->id_map[dist_info->id] == BTF_IS_EMBEDDED && in btf_relocate_map_distilled_base()
336 base_t->size != dist_t->size) 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()
352 …base BTF type '%s' [%u], size %u has multiple candidates of the same size (ids [%u, %u]) in base B… in btf_relocate_map_distilled_base()
353 base_info.name, dist_info->id, in btf_relocate_map_distilled_base()
354 base_t->size, id, r->id_map[dist_info->id]); in btf_relocate_map_distilled_base()
355 err = -EINVAL; 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()
363 /* ensure all distilled BTF ids now have a mapping... */ 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()
373 err = -EINVAL; in btf_relocate_map_distilled_base()
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()
398 if (t->name_off) in btf_relocate_validate_distilled_base()
402 return -EINVAL; in btf_relocate_validate_distilled_base()
406 return -EINVAL; in btf_relocate_validate_distilled_base()
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()
433 return -ENOENT; in btf_relocate_rewrite_strs()
442 * at base_btf, and type ids, strings adjusted accordingly.
455 return -EINVAL; in btf_relocate()
459 r.nr_split_types = nr_types - r.nr_dist_base_types; in btf_relocate()
464 r.str_map = calloc(btf_header(r.dist_base_btf)->str_len, sizeof(*r.str_map)); 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()
470 err = -ENOMEM; in btf_relocate()
478 /* Split BTF ids need to be adjusted as base and distilled base in btf_relocate()
483 r.id_map[id] = id + r.nr_base_types - r.nr_dist_base_types; in btf_relocate()
485 /* Build a map from distilled base ids to actual base BTF ids; it is used in btf_relocate()
493 /* Next, rewrite type ids in split BTF, replacing split ids with updated in btf_relocate()
494 * ids based on number of types in base BTF, and base ids with in btf_relocate()
495 * relocated ids from base_btf. in btf_relocate()