Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge branch 'libbpf: Add btf__type_cnt() and btf__raw_data() APIs'

Hengqi Chen says:

====================

Add btf__type_cnt() and btf__raw_data() APIs and deprecate
btf__get_nr_type() and btf__get_raw_data() since the old APIs
don't follow libbpf naming convention. Also update tools/selftests
to use these new APIs. This is part of effort towards libbpf v1.0

v1->v2:
- Update commit message, deprecate the old APIs in libbpf v0.7 (Andrii)
- Separate changes in tools/ to individual patches (Andrii)
====================

Signed-off-by: Andrii Nakryiko <andrii@kernel.org>

+97 -83
+6 -6
tools/bpf/bpftool/btf.c
··· 329 329 printf("\n\ttype_id=%u offset=%u size=%u", 330 330 v->type, v->offset, v->size); 331 331 332 - if (v->type <= btf__get_nr_types(btf)) { 332 + if (v->type < btf__type_cnt(btf)) { 333 333 vt = btf__type_by_id(btf, v->type); 334 334 printf(" (%s '%s')", 335 335 btf_kind_str[btf_kind_safe(btf_kind(vt))], ··· 390 390 } 391 391 } else { 392 392 const struct btf *base; 393 - int cnt = btf__get_nr_types(btf); 393 + int cnt = btf__type_cnt(btf); 394 394 int start_id = 1; 395 395 396 396 base = btf__base_btf(btf); 397 397 if (base) 398 - start_id = btf__get_nr_types(base) + 1; 398 + start_id = btf__type_cnt(base); 399 399 400 - for (i = start_id; i <= cnt; i++) { 400 + for (i = start_id; i < cnt; i++) { 401 401 t = btf__type_by_id(btf, i); 402 402 dump_btf_type(btf, i, t); 403 403 } ··· 440 440 goto done; 441 441 } 442 442 } else { 443 - int cnt = btf__get_nr_types(btf); 443 + int cnt = btf__type_cnt(btf); 444 444 445 - for (i = 1; i <= cnt; i++) { 445 + for (i = 1; i < cnt; i++) { 446 446 err = btf_dump__dump_type(d, i); 447 447 if (err) 448 448 goto done;
+2 -2
tools/bpf/bpftool/gen.c
··· 211 211 static int codegen_datasecs(struct bpf_object *obj, const char *obj_name) 212 212 { 213 213 struct btf *btf = bpf_object__btf(obj); 214 - int n = btf__get_nr_types(btf); 214 + int n = btf__type_cnt(btf); 215 215 struct btf_dump *d; 216 216 struct bpf_map *map; 217 217 const struct btf_type *sec; ··· 233 233 continue; 234 234 235 235 sec = NULL; 236 - for (i = 1; i <= n; i++) { 236 + for (i = 1; i < n; i++) { 237 237 const struct btf_type *t = btf__type_by_id(btf, i); 238 238 const char *name; 239 239
+2 -2
tools/bpf/resolve_btfids/main.c
··· 502 502 } 503 503 504 504 err = -1; 505 - nr_types = btf__get_nr_types(btf); 505 + nr_types = btf__type_cnt(btf); 506 506 507 507 /* 508 508 * Iterate all the BTF types and search for collected symbol IDs. 509 509 */ 510 - for (type_id = 1; type_id <= nr_types; type_id++) { 510 + for (type_id = 1; type_id < nr_types; type_id++) { 511 511 const struct btf_type *type; 512 512 struct rb_root *root; 513 513 struct btf_id *id;
+22 -14
tools/lib/bpf/btf.c
··· 57 57 * representation is broken up into three independently allocated 58 58 * memory regions to be able to modify them independently. 59 59 * raw_data is nulled out at that point, but can be later allocated 60 - * and cached again if user calls btf__get_raw_data(), at which point 60 + * and cached again if user calls btf__raw_data(), at which point 61 61 * raw_data will contain a contiguous copy of header, types, and 62 62 * strings: 63 63 * ··· 435 435 return btf->start_id + btf->nr_types - 1; 436 436 } 437 437 438 + __u32 btf__type_cnt(const struct btf *btf) 439 + { 440 + return btf->start_id + btf->nr_types; 441 + } 442 + 438 443 const struct btf *btf__base_btf(const struct btf *btf) 439 444 { 440 445 return btf->base_btf; ··· 471 466 if (btf->base_btf && btf->base_btf->ptr_sz > 0) 472 467 return btf->base_btf->ptr_sz; 473 468 474 - n = btf__get_nr_types(btf); 475 - for (i = 1; i <= n; i++) { 469 + n = btf__type_cnt(btf); 470 + for (i = 1; i < n; i++) { 476 471 t = btf__type_by_id(btf, i); 477 472 if (!btf_is_int(t)) 478 473 continue; ··· 689 684 690 685 __s32 btf__find_by_name(const struct btf *btf, const char *type_name) 691 686 { 692 - __u32 i, nr_types = btf__get_nr_types(btf); 687 + __u32 i, nr_types = btf__type_cnt(btf); 693 688 694 689 if (!strcmp(type_name, "void")) 695 690 return 0; 696 691 697 - for (i = 1; i <= nr_types; i++) { 692 + for (i = 1; i < nr_types; i++) { 698 693 const struct btf_type *t = btf__type_by_id(btf, i); 699 694 const char *name = btf__name_by_offset(btf, t->name_off); 700 695 ··· 708 703 static __s32 btf_find_by_name_kind(const struct btf *btf, int start_id, 709 704 const char *type_name, __u32 kind) 710 705 { 711 - __u32 i, nr_types = btf__get_nr_types(btf); 706 + __u32 i, nr_types = btf__type_cnt(btf); 712 707 713 708 if (kind == BTF_KIND_UNKN || !strcmp(type_name, "void")) 714 709 return 0; 715 710 716 - for (i = start_id; i <= nr_types; i++) { 711 + for (i = start_id; i < nr_types; i++) { 717 712 const struct btf_type *t = btf__type_by_id(btf, i); 718 713 const char *name; 719 714 ··· 786 781 787 782 if (base_btf) { 788 783 btf->base_btf = base_btf; 789 - btf->start_id = btf__get_nr_types(base_btf) + 1; 784 + btf->start_id = btf__type_cnt(base_btf); 790 785 btf->start_str_off = base_btf->hdr->str_len; 791 786 } 792 787 ··· 836 831 837 832 if (base_btf) { 838 833 btf->base_btf = base_btf; 839 - btf->start_id = btf__get_nr_types(base_btf) + 1; 834 + btf->start_id = btf__type_cnt(base_btf); 840 835 btf->start_str_off = base_btf->hdr->str_len; 841 836 } 842 837 ··· 1229 1224 return NULL; 1230 1225 } 1231 1226 1232 - const void *btf__get_raw_data(const struct btf *btf_ro, __u32 *size) 1227 + const void *btf__raw_data(const struct btf *btf_ro, __u32 *size) 1233 1228 { 1234 1229 struct btf *btf = (struct btf *)btf_ro; 1235 1230 __u32 data_sz; ··· 1237 1232 1238 1233 data = btf_get_raw_data(btf, &data_sz, btf->swapped_endian); 1239 1234 if (!data) 1240 - return errno = -ENOMEM, NULL; 1235 + return errno = ENOMEM, NULL; 1241 1236 1242 1237 btf->raw_size = data_sz; 1243 1238 if (btf->swapped_endian) ··· 1247 1242 *size = data_sz; 1248 1243 return data; 1249 1244 } 1245 + 1246 + __attribute__((alias("btf__raw_data"))) 1247 + const void *btf__get_raw_data(const struct btf *btf, __u32 *size); 1250 1248 1251 1249 const char *btf__str_by_offset(const struct btf *btf, __u32 offset) 1252 1250 { ··· 1659 1651 old_strs_len = btf->hdr->str_len; 1660 1652 1661 1653 data_sz = src_btf->hdr->type_len; 1662 - cnt = btf__get_nr_types(src_btf); 1654 + cnt = btf__type_cnt(src_btf) - 1; 1663 1655 1664 1656 /* pre-allocate enough memory for new types */ 1665 1657 t = btf_add_type_mem(btf, data_sz); ··· 1976 1968 1977 1969 static struct btf_type *btf_last_type(struct btf *btf) 1978 1970 { 1979 - return btf_type_by_id(btf, btf__get_nr_types(btf)); 1971 + return btf_type_by_id(btf, btf__type_cnt(btf) - 1); 1980 1972 } 1981 1973 1982 1974 /* ··· 3182 3174 goto done; 3183 3175 } 3184 3176 3185 - type_cnt = btf__get_nr_types(btf) + 1; 3177 + type_cnt = btf__type_cnt(btf); 3186 3178 d->map = malloc(sizeof(__u32) * type_cnt); 3187 3179 if (!d->map) { 3188 3180 err = -ENOMEM;
+4
tools/lib/bpf/btf.h
··· 132 132 const char *type_name); 133 133 LIBBPF_API __s32 btf__find_by_name_kind(const struct btf *btf, 134 134 const char *type_name, __u32 kind); 135 + LIBBPF_DEPRECATED_SINCE(0, 7, "use btf__type_cnt() instead; note that btf__get_nr_types() == btf__type_cnt() - 1") 135 136 LIBBPF_API __u32 btf__get_nr_types(const struct btf *btf); 137 + LIBBPF_API __u32 btf__type_cnt(const struct btf *btf); 136 138 LIBBPF_API const struct btf *btf__base_btf(const struct btf *btf); 137 139 LIBBPF_API const struct btf_type *btf__type_by_id(const struct btf *btf, 138 140 __u32 id); ··· 147 145 LIBBPF_API int btf__align_of(const struct btf *btf, __u32 id); 148 146 LIBBPF_API int btf__fd(const struct btf *btf); 149 147 LIBBPF_API void btf__set_fd(struct btf *btf, int fd); 148 + LIBBPF_DEPRECATED_SINCE(0, 7, "use btf__raw_data() instead") 150 149 LIBBPF_API const void *btf__get_raw_data(const struct btf *btf, __u32 *size); 150 + LIBBPF_API const void *btf__raw_data(const struct btf *btf, __u32 *size); 151 151 LIBBPF_API const char *btf__name_by_offset(const struct btf *btf, __u32 offset); 152 152 LIBBPF_API const char *btf__str_by_offset(const struct btf *btf, __u32 offset); 153 153 LIBBPF_API int btf__get_map_kv_tids(const struct btf *btf, const char *map_name,
+4 -4
tools/lib/bpf/btf_dump.c
··· 188 188 189 189 static int btf_dump_resize(struct btf_dump *d) 190 190 { 191 - int err, last_id = btf__get_nr_types(d->btf); 191 + int err, last_id = btf__type_cnt(d->btf) - 1; 192 192 193 193 if (last_id <= d->last_id) 194 194 return 0; ··· 262 262 { 263 263 int err, i; 264 264 265 - if (id > btf__get_nr_types(d->btf)) 265 + if (id >= btf__type_cnt(d->btf)) 266 266 return libbpf_err(-EINVAL); 267 267 268 268 err = btf_dump_resize(d); ··· 294 294 */ 295 295 static int btf_dump_mark_referenced(struct btf_dump *d) 296 296 { 297 - int i, j, n = btf__get_nr_types(d->btf); 297 + int i, j, n = btf__type_cnt(d->btf); 298 298 const struct btf_type *t; 299 299 __u16 vlen; 300 300 301 - for (i = d->last_id + 1; i <= n; i++) { 301 + for (i = d->last_id + 1; i < n; i++) { 302 302 t = btf__type_by_id(d->btf, i); 303 303 vlen = btf_vlen(t); 304 304
+18 -18
tools/lib/bpf/libbpf.c
··· 2497 2497 return -EINVAL; 2498 2498 } 2499 2499 2500 - nr_types = btf__get_nr_types(obj->btf); 2501 - for (i = 1; i <= nr_types; i++) { 2500 + nr_types = btf__type_cnt(obj->btf); 2501 + for (i = 1; i < nr_types; i++) { 2502 2502 t = btf__type_by_id(obj->btf, i); 2503 2503 if (!btf_is_datasec(t)) 2504 2504 continue; ··· 2579 2579 struct btf_type *t; 2580 2580 int i, j, vlen; 2581 2581 2582 - for (i = 1; i <= btf__get_nr_types(btf); i++) { 2582 + for (i = 1; i < btf__type_cnt(btf); i++) { 2583 2583 t = (struct btf_type *)btf__type_by_id(btf, i); 2584 2584 2585 2585 if ((!has_datasec && btf_is_var(t)) || (!has_decl_tag && btf_is_decl_tag(t))) { ··· 2763 2763 static int btf_finalize_data(struct bpf_object *obj, struct btf *btf) 2764 2764 { 2765 2765 int err = 0; 2766 - __u32 i, n = btf__get_nr_types(btf); 2766 + __u32 i, n = btf__type_cnt(btf); 2767 2767 2768 - for (i = 1; i <= n; i++) { 2768 + for (i = 1; i < n; i++) { 2769 2769 struct btf_type *t = btf_type_by_id(btf, i); 2770 2770 2771 2771 /* Loader needs to fix up some of the things compiler ··· 2905 2905 if (!prog->mark_btf_static || !prog_is_subprog(obj, prog)) 2906 2906 continue; 2907 2907 2908 - n = btf__get_nr_types(obj->btf); 2909 - for (j = 1; j <= n; j++) { 2908 + n = btf__type_cnt(obj->btf); 2909 + for (j = 1; j < n; j++) { 2910 2910 t = btf_type_by_id(obj->btf, j); 2911 2911 if (!btf_is_func(t) || btf_func_linkage(t) != BTF_FUNC_GLOBAL) 2912 2912 continue; ··· 2926 2926 __u32 sz; 2927 2927 2928 2928 /* clone BTF to sanitize a copy and leave the original intact */ 2929 - raw_data = btf__get_raw_data(obj->btf, &sz); 2929 + raw_data = btf__raw_data(obj->btf, &sz); 2930 2930 kern_btf = btf__new(raw_data, sz); 2931 2931 err = libbpf_get_error(kern_btf); 2932 2932 if (err) ··· 2939 2939 2940 2940 if (obj->gen_loader) { 2941 2941 __u32 raw_size = 0; 2942 - const void *raw_data = btf__get_raw_data(kern_btf, &raw_size); 2942 + const void *raw_data = btf__raw_data(kern_btf, &raw_size); 2943 2943 2944 2944 if (!raw_data) 2945 2945 return -ENOMEM; ··· 3350 3350 if (!btf) 3351 3351 return -ESRCH; 3352 3352 3353 - n = btf__get_nr_types(btf); 3354 - for (i = 1; i <= n; i++) { 3353 + n = btf__type_cnt(btf); 3354 + for (i = 1; i < n; i++) { 3355 3355 t = btf__type_by_id(btf, i); 3356 3356 3357 3357 if (!btf_is_var(t) && !btf_is_func(t)) ··· 3382 3382 if (!btf) 3383 3383 return -ESRCH; 3384 3384 3385 - n = btf__get_nr_types(btf); 3386 - for (i = 1; i <= n; i++) { 3385 + n = btf__type_cnt(btf); 3386 + for (i = 1; i < n; i++) { 3387 3387 t = btf__type_by_id(btf, i); 3388 3388 3389 3389 if (!btf_is_datasec(t)) ··· 3467 3467 const struct btf_type *t; 3468 3468 int i, n; 3469 3469 3470 - n = btf__get_nr_types(btf); 3471 - for (i = 1; i <= n; i++) { 3470 + n = btf__type_cnt(btf); 3471 + for (i = 1; i < n; i++) { 3472 3472 t = btf__type_by_id(btf, i); 3473 3473 3474 3474 if (btf_is_int(t) && btf_int_bits(t) == 32) ··· 5076 5076 size_t targ_essent_len; 5077 5077 int n, i; 5078 5078 5079 - n = btf__get_nr_types(targ_btf); 5080 - for (i = targ_start_id; i <= n; i++) { 5079 + n = btf__type_cnt(targ_btf); 5080 + for (i = targ_start_id; i < n; i++) { 5081 5081 t = btf__type_by_id(targ_btf, i); 5082 5082 if (btf_kind(t) != btf_kind(local_cand->t)) 5083 5083 continue; ··· 5252 5252 err = bpf_core_add_cands(&local_cand, local_essent_len, 5253 5253 obj->btf_modules[i].btf, 5254 5254 obj->btf_modules[i].name, 5255 - btf__get_nr_types(obj->btf_vmlinux) + 1, 5255 + btf__type_cnt(obj->btf_vmlinux), 5256 5256 cands); 5257 5257 if (err) 5258 5258 goto err_out;
+2
tools/lib/bpf/libbpf.map
··· 395 395 bpf_object__prev_program; 396 396 btf__add_btf; 397 397 btf__add_decl_tag; 398 + btf__raw_data; 399 + btf__type_cnt; 398 400 } LIBBPF_0.5.0;
+14 -14
tools/lib/bpf/linker.c
··· 920 920 { 921 921 struct btf *btf = ctx; 922 922 923 - if (*type_id > btf__get_nr_types(btf)) 923 + if (*type_id >= btf__type_cnt(btf)) 924 924 return -EINVAL; 925 925 926 926 return 0; ··· 947 947 if (!obj->btf) 948 948 return 0; 949 949 950 - n = btf__get_nr_types(obj->btf); 951 - for (i = 1; i <= n; i++) { 950 + n = btf__type_cnt(obj->btf); 951 + for (i = 1; i < n; i++) { 952 952 t = btf_type_by_id(obj->btf, i); 953 953 954 954 err = err ?: btf_type_visit_type_ids(t, check_btf_type_id, obj->btf); ··· 1658 1658 return -EINVAL; 1659 1659 } 1660 1660 1661 - n = btf__get_nr_types(obj->btf); 1662 - for (i = 1; i <= n; i++) { 1661 + n = btf__type_cnt(obj->btf); 1662 + for (i = 1; i < n; i++) { 1663 1663 t = btf__type_by_id(obj->btf, i); 1664 1664 1665 1665 /* some global and extern FUNCs and VARs might not be associated with any ··· 2130 2130 if (!obj->btf) 2131 2131 return 0; 2132 2132 2133 - n = btf__get_nr_types(obj->btf); 2134 - for (i = 1; i <= n; i++) { 2133 + n = btf__type_cnt(obj->btf); 2134 + for (i = 1; i < n; i++) { 2135 2135 struct btf_var_secinfo *vi; 2136 2136 struct btf_type *t; 2137 2137 ··· 2234 2234 if (!obj->btf) 2235 2235 return 0; 2236 2236 2237 - start_id = btf__get_nr_types(linker->btf) + 1; 2238 - n = btf__get_nr_types(obj->btf); 2237 + start_id = btf__type_cnt(linker->btf); 2238 + n = btf__type_cnt(obj->btf); 2239 2239 2240 2240 obj->btf_type_map = calloc(n + 1, sizeof(int)); 2241 2241 if (!obj->btf_type_map) 2242 2242 return -ENOMEM; 2243 2243 2244 - for (i = 1; i <= n; i++) { 2244 + for (i = 1; i < n; i++) { 2245 2245 struct glob_sym *glob_sym = NULL; 2246 2246 2247 2247 t = btf__type_by_id(obj->btf, i); ··· 2296 2296 } 2297 2297 2298 2298 /* remap all the types except DATASECs */ 2299 - n = btf__get_nr_types(linker->btf); 2300 - for (i = start_id; i <= n; i++) { 2299 + n = btf__type_cnt(linker->btf); 2300 + for (i = start_id; i < n; i++) { 2301 2301 struct btf_type *dst_t = btf_type_by_id(linker->btf, i); 2302 2302 2303 2303 if (btf_type_visit_type_ids(dst_t, remap_type_id, obj->btf_type_map)) ··· 2656 2656 __u32 raw_sz; 2657 2657 2658 2658 /* bail out if no BTF data was produced */ 2659 - if (btf__get_nr_types(linker->btf) == 0) 2659 + if (btf__type_cnt(linker->btf) == 1) 2660 2660 return 0; 2661 2661 2662 2662 for (i = 1; i < linker->sec_cnt; i++) { ··· 2693 2693 } 2694 2694 2695 2695 /* Emit .BTF section */ 2696 - raw_data = btf__get_raw_data(linker->btf, &raw_sz); 2696 + raw_data = btf__raw_data(linker->btf, &raw_sz); 2697 2697 if (!raw_data) 2698 2698 return -ENOMEM; 2699 2699
+1 -1
tools/perf/util/bpf-event.c
··· 110 110 u32 data_size; 111 111 const void *data; 112 112 113 - data = btf__get_raw_data(btf, &data_size); 113 + data = btf__raw_data(btf, &data_size); 114 114 115 115 node = malloc(data_size + sizeof(struct btf_node)); 116 116 if (!node)
+2 -2
tools/testing/selftests/bpf/btf_helpers.c
··· 215 215 int i; 216 216 bool ok = true; 217 217 218 - ASSERT_EQ(btf__get_nr_types(btf), nr_types, "btf_nr_types"); 218 + ASSERT_EQ(btf__type_cnt(btf) - 1, nr_types, "btf_nr_types"); 219 219 220 220 for (i = 1; i <= nr_types; i++) { 221 221 if (!ASSERT_STREQ(btf_type_raw_dump(btf, i), exp_types[i - 1], "raw_dump")) ··· 254 254 return NULL; 255 255 } 256 256 257 - for (i = 1; i <= btf__get_nr_types(btf); i++) { 257 + for (i = 1; i < btf__type_cnt(btf); i++) { 258 258 err = btf_dump__dump_type(d, i); 259 259 if (err) { 260 260 fprintf(stderr, "Failed to dump type [%d]: %d\n", i, err);
+5 -5
tools/testing/selftests/bpf/prog_tests/btf.c
··· 7274 7274 goto done; 7275 7275 } 7276 7276 7277 - test_btf_data = btf__get_raw_data(test_btf, &test_btf_size); 7278 - expect_btf_data = btf__get_raw_data(expect_btf, &expect_btf_size); 7277 + test_btf_data = btf__raw_data(test_btf, &test_btf_size); 7278 + expect_btf_data = btf__raw_data(expect_btf, &expect_btf_size); 7279 7279 if (CHECK(test_btf_size != expect_btf_size, 7280 7280 "test_btf_size:%u != expect_btf_size:%u", 7281 7281 test_btf_size, expect_btf_size)) { ··· 7329 7329 expect_str_cur += expect_len + 1; 7330 7330 } 7331 7331 7332 - test_nr_types = btf__get_nr_types(test_btf); 7333 - expect_nr_types = btf__get_nr_types(expect_btf); 7332 + test_nr_types = btf__type_cnt(test_btf); 7333 + expect_nr_types = btf__type_cnt(expect_btf); 7334 7334 if (CHECK(test_nr_types != expect_nr_types, 7335 7335 "test_nr_types:%u != expect_nr_types:%u", 7336 7336 test_nr_types, expect_nr_types)) { ··· 7338 7338 goto done; 7339 7339 } 7340 7340 7341 - for (i = 1; i <= test_nr_types; i++) { 7341 + for (i = 1; i < test_nr_types; i++) { 7342 7342 const struct btf_type *test_type, *expect_type; 7343 7343 int test_size, expect_size; 7344 7344
+4 -4
tools/testing/selftests/bpf/prog_tests/btf_dump.c
··· 27 27 static int btf_dump_all_types(const struct btf *btf, 28 28 const struct btf_dump_opts *opts) 29 29 { 30 - size_t type_cnt = btf__get_nr_types(btf); 30 + size_t type_cnt = btf__type_cnt(btf); 31 31 struct btf_dump *d; 32 32 int err = 0, id; 33 33 ··· 36 36 if (err) 37 37 return err; 38 38 39 - for (id = 1; id <= type_cnt; id++) { 39 + for (id = 1; id < type_cnt; id++) { 40 40 err = btf_dump__dump_type(d, id); 41 41 if (err) 42 42 goto done; ··· 171 171 err = btf__add_field(btf, "x", 2, 0, 0); 172 172 ASSERT_OK(err, "field_ok"); 173 173 174 - for (i = 1; i <= btf__get_nr_types(btf); i++) { 174 + for (i = 1; i < btf__type_cnt(btf); i++) { 175 175 err = btf_dump__dump_type(d, i); 176 176 ASSERT_OK(err, "dump_type_ok"); 177 177 } ··· 210 210 err = btf__add_field(btf, "s", 3, 32, 0); 211 211 ASSERT_OK(err, "field_ok"); 212 212 213 - for (i = 1; i <= btf__get_nr_types(btf); i++) { 213 + for (i = 1; i < btf__type_cnt(btf); i++) { 214 214 err = btf_dump__dump_type(d, i); 215 215 ASSERT_OK(err, "dump_type_ok"); 216 216 }
+6 -6
tools/testing/selftests/bpf/prog_tests/btf_endian.c
··· 32 32 ASSERT_EQ(btf__endianness(btf), swap_endian, "endian"); 33 33 34 34 /* Get raw BTF data in non-native endianness... */ 35 - raw_data = btf__get_raw_data(btf, &raw_sz); 35 + raw_data = btf__raw_data(btf, &raw_sz); 36 36 if (!ASSERT_OK_PTR(raw_data, "raw_data_inverted")) 37 37 goto err_out; 38 38 ··· 42 42 goto err_out; 43 43 44 44 ASSERT_EQ(btf__endianness(swap_btf), swap_endian, "endian"); 45 - ASSERT_EQ(btf__get_nr_types(swap_btf), btf__get_nr_types(btf), "nr_types"); 45 + ASSERT_EQ(btf__type_cnt(swap_btf), btf__type_cnt(btf), "nr_types"); 46 46 47 - swap_raw_data = btf__get_raw_data(swap_btf, &swap_raw_sz); 47 + swap_raw_data = btf__raw_data(swap_btf, &swap_raw_sz); 48 48 if (!ASSERT_OK_PTR(swap_raw_data, "swap_raw_data")) 49 49 goto err_out; 50 50 ··· 58 58 59 59 /* swap it back to native endianness */ 60 60 btf__set_endianness(swap_btf, endian); 61 - swap_raw_data = btf__get_raw_data(swap_btf, &swap_raw_sz); 61 + swap_raw_data = btf__raw_data(swap_btf, &swap_raw_sz); 62 62 if (!ASSERT_OK_PTR(swap_raw_data, "swap_raw_data")) 63 63 goto err_out; 64 64 ··· 75 75 swap_btf = NULL; 76 76 77 77 btf__set_endianness(btf, swap_endian); 78 - raw_data = btf__get_raw_data(btf, &raw_sz); 78 + raw_data = btf__raw_data(btf, &raw_sz); 79 79 if (!ASSERT_OK_PTR(raw_data, "raw_data_inverted")) 80 80 goto err_out; 81 81 ··· 85 85 goto err_out; 86 86 87 87 ASSERT_EQ(btf__endianness(swap_btf), swap_endian, "endian"); 88 - ASSERT_EQ(btf__get_nr_types(swap_btf), btf__get_nr_types(btf), "nr_types"); 88 + ASSERT_EQ(btf__type_cnt(swap_btf), btf__type_cnt(btf), "nr_types"); 89 89 90 90 /* the type should appear as if it was stored in native endianness */ 91 91 t = btf__type_by_id(swap_btf, var_id);
+1 -1
tools/testing/selftests/bpf/prog_tests/btf_split.c
··· 72 72 d = btf_dump__new(btf2, NULL, &opts, btf_dump_printf); 73 73 if (!ASSERT_OK_PTR(d, "btf_dump__new")) 74 74 goto cleanup; 75 - for (i = 1; i <= btf__get_nr_types(btf2); i++) { 75 + for (i = 1; i < btf__type_cnt(btf2); i++) { 76 76 err = btf_dump__dump_type(d, i); 77 77 ASSERT_OK(err, "dump_type_ok"); 78 78 }
+1 -1
tools/testing/selftests/bpf/prog_tests/core_autosize.c
··· 112 112 if (!ASSERT_OK_PTR(f, "btf_fdopen")) 113 113 goto cleanup; 114 114 115 - raw_data = btf__get_raw_data(btf, &raw_sz); 115 + raw_data = btf__raw_data(btf, &raw_sz); 116 116 if (!ASSERT_OK_PTR(raw_data, "raw_data")) 117 117 goto cleanup; 118 118 written = fwrite(raw_data, 1, raw_sz, f);
+1 -1
tools/testing/selftests/bpf/prog_tests/core_reloc.c
··· 381 381 exp->local_anon_void_ptr = -1; 382 382 exp->local_anon_arr = -1; 383 383 384 - for (i = 1; i <= btf__get_nr_types(local_btf); i++) 384 + for (i = 1; i < btf__type_cnt(local_btf); i++) 385 385 { 386 386 t = btf__type_by_id(local_btf, i); 387 387 /* we are interested only in anonymous types */
+2 -2
tools/testing/selftests/bpf/prog_tests/resolve_btfids.c
··· 106 106 "Failed to load BTF from btf_data.o\n")) 107 107 return -1; 108 108 109 - nr = btf__get_nr_types(btf); 109 + nr = btf__type_cnt(btf); 110 110 111 - for (type_id = 1; type_id <= nr; type_id++) { 111 + for (type_id = 1; type_id < nr; type_id++) { 112 112 if (__resolve_symbol(btf, type_id)) 113 113 break; 114 114 }