> On Oct 4, 2021, at 11:47 PM, andrii.nakryiko@xxxxxxxxx wrote: > > From: Andrii Nakryiko <andrii@xxxxxxxxxx> > > Add a bulk copying api, btf__add_btf(), that speeds up and simplifies > appending entire contents of one BTF object to another one, taking care > of copying BTF type data, adjusting resulting BTF type IDs according to > their new locations in the destination BTF object, as well as copying > and deduplicating all the referenced strings and updating all the string > offsets in new BTF types as appropriate. > > This API is intended to be used from tools that are generating and > otherwise manipulating BTFs generically, such as pahole. In pahole's > case, this API is useful for speeding up parallelized BTF encoding, as > it allows pahole to offload all the intricacies of BTF type copying to > libbpf and handle the parallelization aspects of the process. > > Cc: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx> > Signed-off-by: Andrii Nakryiko <andrii@xxxxxxxxxx> Acked-by: Song Liu <songliubraving@xxxxxx> with on typo below. > --- > tools/lib/bpf/btf.c | 114 ++++++++++++++++++++++++++++++++++++++- > tools/lib/bpf/btf.h | 22 ++++++++ > tools/lib/bpf/libbpf.map | 1 + > 3 files changed, 135 insertions(+), 2 deletions(-) [...] > diff --git a/tools/lib/bpf/btf.h b/tools/lib/bpf/btf.h > index 2cfe31327920..823e7067d34e 100644 > --- a/tools/lib/bpf/btf.h > +++ b/tools/lib/bpf/btf.h > @@ -173,6 +173,28 @@ LIBBPF_API int btf__find_str(struct btf *btf, const char *s); > LIBBPF_API int btf__add_str(struct btf *btf, const char *s); > LIBBPF_API int btf__add_type(struct btf *btf, const struct btf *src_btf, > const struct btf_type *src_type); > +/** > + * @brief **btf__add_btf()** appends all the BTF types from *src_btf* into *btf* > + * @param btf BTF object which all the BTF types and strings are added to > + * @param src_btf BTF object which all BTF types and referenced strings are copied from > + * @return BTF type ID of the first appended BTF type, or negative error code > + * > + * **btf__add_btf()** can be used to simply and efficiently append the entire > + * contents of one BTF object to another one. All the BTF type data is copied > + * over, all referenced type IDs are adjusted by adding a necessary ID offset. > + * Only strings referenced from BTF types are copied over and deduplicated, so > + * if there were some unused strings in *src_btf*, those won't be copied over, > + * which is consistent with the general string deduplication semantics of BTF > + * writing APIs. > + * > + * If any error is encountered during this process, the contents of *btf* is > + * left intact, which means that **btf__add_btf()** follows the transactional > + * semantics and the operation as a whole is all-or-nothing. > + * > + * *src_btf* has to be non-split BTF, as of now copying types from split BTF > + * is not supported and will result in -OPNOTSUP error code returned. ^^^ typo: -ENOTSUP > > + */ > +LIBBPF_API int btf__add_btf(struct btf *btf, const struct btf *src_btf); > > LIBBPF_API int btf__add_int(struct btf *btf, const char *name, size_t byte_sz, int encoding); > LIBBPF_API int btf__add_float(struct btf *btf, const char *name, size_t byte_sz); > diff --git a/tools/lib/bpf/libbpf.map b/tools/lib/bpf/libbpf.map > index 9e649cf9e771..f6b0db1e8c8b 100644 > --- a/tools/lib/bpf/libbpf.map > +++ b/tools/lib/bpf/libbpf.map > @@ -389,5 +389,6 @@ LIBBPF_0.5.0 { > > LIBBPF_0.6.0 { > global: > + btf__add_btf; > btf__add_tag; > } LIBBPF_0.5.0; > -- > 2.30.2 >