Re: [PATCH bpf-next v2 4/4] resolve_btfids: change in-place update with raw binary output

From: Eduard Zingerman

Date: Thu Dec 04 2025 - 13:06:24 EST


On Thu, 2025-12-04 at 09:29 -0800, Ihor Solodrai wrote:

[...]

> Ok, it seems you're conflating two separate issues.
>
> There is a requirement to *link* .BTF section into vmlinux, because it
> must have a SHF_ALLOC flag, which makes objcopying the section data
> insufficient: linker has to do some magic under the hood.
>
> The patch doesn't change this behavior, and this was (and is) covered
> in the script comments.
>
> A separate issue is what resolve_btfids does: updates ELF in-place
> (before the patch) or outputs detached section data (after patch).
>
> The paragraph in the commit message attempted to explain the decision
> to output raw section data. And apparently I did a bad job of
> that. I'll rewrite this part it in the next revision.
>
> And I feel I should clarify that I didn't claim that libelf is buggy.
> I meant that using it is complicated, which makes resolve_btfids buggy.

So, pahole does the following:
- elf_begin(fildes: fd, cmd: ELF_C_RDWR, ref: NULL);
- selects a section to modify and modifies it
- elf_flagdata(data: btf_data, cmd: ELF_C_SET, flags: ELF_F_DIRTY);
- elf_update(elf, cmd: ELF_C_WRITE)
- elf_end(elf)

What exactly is complicated about that?

[...]