Em Fri, Feb 15, 2019 at 09:25:48AM -0800, Andrii Nakryiko escreveu: > On Fri, Feb 15, 2019 at 9:15 AM Arnaldo Carvalho de Melo <arnaldo.melo@xxxxxxxxx> wrote: > > Em Thu, Feb 14, 2019 at 08:37:51PM -0800, Andrii Nakryiko escreveu: > > > On Thu, Feb 14, 2019 at 6:01 AM Arnaldo Carvalho de Melo <arnaldo.melo@xxxxxxxxx> wrote: > > > Yes, libbpf's struct btf is immutable read-only view of .BTF section > > > that can come from either file or kernel. When I'll be adding BTF > > > writing (encoding) API, it probably will be done using something > > > similar to pahole's struct btf, that supports dynamic growth of types > > Ok, I noticed that libbpf's btf__new() does load things into the kernel, > > perhaps we should have it not do that and instead have some other method > > for asking it to send the data to kernel, i.e.: > > struct btf *btf = btf__new(); > > int err = btf__load_to_kernel(btf, data, size); > > Or have multiple constructors, each specifying what it actually does, > > i.e.: > > To get a btf data + size and insert it into the kernel, getting its fd, > > etc: > > struct btf *btf = btf__new_to_kernel(data, size); > > For asking for BTF info that is already in the kernel to be obtained for > > tooling to parse maps in running bpf programs: > > struct btf *btf = btf__new_from_kernel(fd); > > And for the pahole case it would be: > > struct btf *btf = btf__new_from_elf(file-with-BTF-ELF-section) > > that would then be used to do the encoding, etc. > We already did that a couple of days ago, that code wasn't yet > mirrored into github.com/libbpf/libbpf until yesterday (it was merged > this morning). We now have btf__new(data, size) that just constructs > in-memory BTF struct with index for types. And we have > btf__load(struct btf* btf) that can load that into kernel. cool > We already have equivalent of btf__new_from_kernel(fd) -- btf__get_from_id(fd). cool, if it allocates space for sizeof(*btf) and returns this newly allocated object, then please consider renaming it to btf__new_from_id(fd). > Adding something akin to btf__new_from_elf() might be a good idea as > well, for completeness. Its nice to be on the same page :-) <SNIP> > > > > @@ -645,7 +636,7 @@ static int btf__write_elf(struct btf *btf) > > > > llvm_objcopy = "llvm-objcopy"; > > > > > > > > /* Use objcopy to add a .BTF section */ > > > > - snprintf(tmp_fn, sizeof(tmp_fn), "%s.btf", btf->filename); > > > > + snprintf(tmp_fn, sizeof(tmp_fn), "%s.btfe", btfe->filename); > > > > > > This is probably unintentional change, though not a problem per se. > > > > Eagle eyes, I'll fix that. > :) - Arnaldo