On Fri, Feb 5, 2021 at 5:42 AM Giuliano Procida <gprocida@xxxxxxxxxx> wrote: > > pahole -J uses libelf directly when updating a .BTF section. However, > it uses llvm-objcopy to add .BTF sections. This commit switches to > using libelf for both cases. > > This eliminates pahole's dependency on llvm-objcopy. One unfortunate > side-effect is that vmlinux actually increases in size. It seems that > llvm-objcopy modifies the .strtab section, discarding many strings. I > speculate that is it discarding strings not referenced from .symtab > and updating the references therein. > > Layout is left completely up to libelf and existing section offsets > are likely to change. > > Signed-off-by: Giuliano Procida <gprocida@xxxxxxxxxx> > --- Logic looks correct. One nit below. Acked-by: Andrii Nakryiko <andrii@xxxxxxxxxx> > libbtf.c | 127 +++++++++++++++++++++++++++++++++++-------------------- > 1 file changed, 81 insertions(+), 46 deletions(-) > > diff --git a/libbtf.c b/libbtf.c > index 4ae7150..9f4abb3 100644 > --- a/libbtf.c > +++ b/libbtf.c > @@ -698,6 +698,7 @@ int32_t btf_elf__add_datasec_type(struct btf_elf *btfe, const char *section_name > > static int btf_elf__write(const char *filename, struct btf *btf) > { > + const char dot_BTF[] = ".BTF"; it's a constant, so more appropriate name would be DOT_BTF, but that "dot_" notation in the name of the variable throws me off, honestly. libbpf is using BTF_SEC_NAME for this, which IMO makes more sense as a name for the constant > GElf_Ehdr ehdr; > Elf_Data *btf_data = NULL; > Elf *elf = NULL; > @@ -705,6 +706,7 @@ static int btf_elf__write(const char *filename, struct btf *btf) > uint32_t raw_btf_size; > int fd, err = -1; > size_t strndx; > + void *str_table = NULL; > > fd = open(filename, O_RDWR); > if (fd < 0) { [...]