On Thu, Feb 4, 2021 at 10:34 AM Giuliano Procida <gprocida@xxxxxxxxxx> wrote: > > Hi. > > On Thu, 4 Feb 2021 at 04:13, Andrii Nakryiko <andrii.nakryiko@xxxxxxxxx> wrote: > > > > On Mon, Feb 1, 2021 at 9:26 AM Giuliano Procida <gprocida@xxxxxxxxxx> wrote: > > > > > > pahole -J needs to do the following to an ELF file: > > > > > > * add or update the ".BTF" section > > > * maybe update the section name string table > > > * update the Section Header Table (SHT) > > > > > > libelf either takes full control of layout or requires the user to > > > specify offset, size and alignment of all new and updated sections and > > > headers. > > > > > > To avoid libelf moving program segments in particular, we position the > > > > It's not clear to me what's wrong with libelf handling all the layout. > > Even if libelf will move program segments around, what's the harm? > > Does it break anything if we just let libelf do this? > > > > It doesn't hurt the userspace case I care about. I've no idea what it > means in terms of vmlinux. > > However, I wrote that text before I discovered that pahole -J isn't > actually used to modify kernel images. > > One thing I haven't tried is to try to make .BTF loadable but leave > placement to libelf. I'd concentrate on getting rid of llvm-objcopy dependency first. Making .BTF loadable is even riskier change and there is no use case that relies on that today, so definitely worth to split that out. > > > > ".BTF" and section name string table (typically named ".shstrtab") > > > sections after all others. The SHT always lives at the end of the file. > > > > > > Note that the last section in an ELF file is normally the section name > > > string table and any ".BTF" section will normally be second last. > > > However, if these sections appear earlier, then we'll waste some space > > > in the ELF file when we rewrite them. > > > > > > Signed-off-by: Giuliano Procida <gprocida@xxxxxxxxxx> > > > --- > > > libbtf.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-- > > > 1 file changed, 62 insertions(+), 2 deletions(-) > > > > > > > [...]