On Tue, Jan 25, 2022 at 8:07 PM Kui-Feng Lee <kuifeng@xxxxxx> wrote: > > Replace deprecated APIs with new ones. > --- LGTM with few nits below. Acked-by: Andrii Nakryiko <andrii@xxxxxxxxxx> > btf_encoder.c | 20 ++++++++++---------- > btf_loader.c | 2 +- > lib/bpf | 2 +- > 3 files changed, 12 insertions(+), 12 deletions(-) > > diff --git a/btf_encoder.c b/btf_encoder.c > index 56a76f5d7275..a31dbe3edc93 100644 > --- a/btf_encoder.c > +++ b/btf_encoder.c > @@ -172,7 +172,7 @@ __attribute ((format (printf, 5, 6))) > static void btf__log_err(const struct btf *btf, int kind, const char *name, > bool output_cr, const char *fmt, ...) > { > - fprintf(stderr, "[%u] %s %s", btf__get_nr_types(btf) + 1, > + fprintf(stderr, "[%u] %s %s", btf__type_cnt(btf), > btf_kind_str[kind], name ?: "(anon)"); > > if (fmt && *fmt) { > @@ -203,7 +203,7 @@ static void btf_encoder__log_type(const struct btf_encoder *encoder, const struc > out = err ? stderr : stdout; > > fprintf(out, "[%u] %s %s", > - btf__get_nr_types(btf), btf_kind_str[kind], > + btf__type_cnt(btf) - 1, btf_kind_str[kind], > btf__printable_name(btf, t->name_off)); > > if (fmt && *fmt) { > @@ -449,10 +449,10 @@ static int btf_encoder__add_field(struct btf_encoder *encoder, const char *name, > int err; > > err = btf__add_field(btf, name, type, offset, bitfield_size); > - t = btf__type_by_id(btf, btf__get_nr_types(btf)); > + t = btf__type_by_id(btf, btf__type_cnt(btf) - 1); > if (err) { > fprintf(stderr, "[%u] %s %s's field '%s' offset=%u bit_size=%u type=%u Error emitting field\n", > - btf__get_nr_types(btf), btf_kind_str[btf_kind(t)], > + btf__type_cnt(btf) - 1, btf_kind_str[btf_kind(t)], > btf__printable_name(btf, t->name_off), > name, offset, bitfield_size, type); > } else { > @@ -899,9 +899,9 @@ static int btf_encoder__write_raw_file(struct btf_encoder *encoder) > const void *raw_btf_data; > int fd, err; > > - raw_btf_data = btf__get_raw_data(encoder->btf, &raw_btf_size); > + raw_btf_data = btf__raw_data(encoder->btf, &raw_btf_size); > if (raw_btf_data == NULL) { > - fprintf(stderr, "%s: btf__get_raw_data failed!\n", __func__); > + fprintf(stderr, "%s: btf__raw_data failed!\n", __func__); > return -1; > } > > @@ -976,7 +976,7 @@ static int btf_encoder__write_elf(struct btf_encoder *encoder) > } > } > > - raw_btf_data = btf__get_raw_data(btf, &raw_btf_size); > + raw_btf_data = btf__raw_data(btf, &raw_btf_size); > > if (btf_data) { > /* Existing .BTF section found */ > @@ -1043,10 +1043,10 @@ int btf_encoder__encode(struct btf_encoder *encoder) > btf_encoder__add_datasec(encoder, PERCPU_SECTION); > > /* Empty file, nothing to do, so... done! */ > - if (btf__get_nr_types(encoder->btf) == 0) > + if (btf__type_cnt(encoder->btf) - 1 == 0) btf__type_cnt() == 1 ? > return 0; > > - if (btf__dedup(encoder->btf, NULL, NULL)) { > + if (btf__dedup(encoder->btf, NULL)) { > fprintf(stderr, "%s: btf__dedup failed!\n", __func__); > return -1; > } > @@ -1403,7 +1403,7 @@ void btf_encoder__delete(struct btf_encoder *encoder) > > int btf_encoder__encode_cu(struct btf_encoder *encoder, struct cu *cu) > { > - uint32_t type_id_off = btf__get_nr_types(encoder->btf); > + uint32_t type_id_off = btf__type_cnt(encoder->btf) - 1; > struct llvm_annotation *annot; > int btf_type_id, tag_type_id; > uint32_t core_id; > diff --git a/btf_loader.c b/btf_loader.c > index b61cadd55127..d9d59aa889a0 100644 > --- a/btf_loader.c > +++ b/btf_loader.c > @@ -399,7 +399,7 @@ static int btf__load_types(struct btf *btf, struct cu *cu) > uint32_t type_index; > int err; > > - for (type_index = 1; type_index <= btf__get_nr_types(btf); type_index++) { > + for (type_index = 1; type_index <= btf__type_cnt(btf) - 1; type_index++) { nit: type_index < btf__type_cnt(btf) would be more natural > const struct btf_type *type_ptr = btf__type_by_id(btf, type_index); > uint32_t type = btf_kind(type_ptr); > > diff --git a/lib/bpf b/lib/bpf > index 94a49850c5ee..393a058d061d 160000 > --- a/lib/bpf > +++ b/lib/bpf > @@ -1 +1 @@ > -Subproject commit 94a49850c5ee61ea02dfcbabf48013391e8cecdf > +Subproject commit 393a058d061d49d5c3055fa9eefafb4c0c31ccc3 > -- > 2.30.2 >