Re: [PATCH] libbpf: poison unresolved weak kfuncs in light skeletons

From: Sid Nayyar

Date: Fri Jun 26 2026 - 12:29:52 EST


On Fri, Jun 26, 2026 at 1:46 AM Alexei Starovoitov
<alexei.starovoitov@xxxxxxxxx> wrote:
>
> On Mon, Jun 22, 2026 at 4:04 PM Siddharth Nayyar <sidnayyar@xxxxxxxxxx> wrote:
> >
> > --- a/tools/lib/bpf/gen_loader.c
> > +++ b/tools/lib/bpf/gen_loader.c
> > @@ -783,10 +783,17 @@ static void emit_relo_kfunc_btf(struct bpf_gen *gen, struct ksym_relo_desc *relo
> > return;
> > /* try to copy from existing bpf_insn */
> > if (kdesc->ref > 1) {
> > - move_blob2blob(gen, insn + offsetof(struct bpf_insn, imm), 4,
> > - kdesc->insn + offsetof(struct bpf_insn, imm));
> > move_blob2blob(gen, insn + offsetof(struct bpf_insn, off), 2,
> > kdesc->insn + offsetof(struct bpf_insn, off));
> > + move_blob2blob(gen, insn + offsetof(struct bpf_insn, imm), 4,
> > + kdesc->insn + offsetof(struct bpf_insn, imm));
>
> why did you change the order?
> Looks like an unrelated change.

Changing the order leaves the value of imm (rather than off) in
BPF_REG_0, which the next instruction consumes when checking if this
value is zero. If I don't do this we will need extra instructions to
load the value of imm before we can check if it is zero.

I hinted this in the comment just after the move_blob2blob() calls by
stating "reuse BPF_REG_0 from move_blob2blob". Please let me know if
this is unclear, I will expand the commentary if necessary.

Regards,
Siddharth Nayyar