Skip to content

Commit d995816

Browse files
kkdwivedianakryiko
authored andcommitted
libbpf: Avoid reload of imm for weak, unresolved, repeating ksym
Alexei pointed out that we can use BPF_REG_0 which already contains imm from move_blob2blob computation. Note that we now compare the second insn's imm, but this should not matter, since both will be zeroed out for the error case for the insn populated earlier. Suggested-by: Alexei Starovoitov <[email protected]> Signed-off-by: Kumar Kartikeya Dwivedi <[email protected]> Signed-off-by: Andrii Nakryiko <[email protected]> Acked-by: Song Liu <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent 0270090 commit d995816

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

tools/lib/bpf/gen_loader.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -795,9 +795,8 @@ static void emit_relo_ksym_btf(struct bpf_gen *gen, struct ksym_relo_desc *relo,
795795
kdesc->insn + offsetof(struct bpf_insn, imm));
796796
move_blob2blob(gen, insn + sizeof(struct bpf_insn) + offsetof(struct bpf_insn, imm), 4,
797797
kdesc->insn + sizeof(struct bpf_insn) + offsetof(struct bpf_insn, imm));
798-
emit(gen, BPF_LDX_MEM(BPF_W, BPF_REG_9, BPF_REG_8, offsetof(struct bpf_insn, imm)));
799-
/* jump over src_reg adjustment if imm is not 0 */
800-
emit(gen, BPF_JMP_IMM(BPF_JNE, BPF_REG_9, 0, 3));
798+
/* jump over src_reg adjustment if imm is not 0, reuse BPF_REG_0 from move_blob2blob */
799+
emit(gen, BPF_JMP_IMM(BPF_JNE, BPF_REG_0, 0, 3));
801800
goto clear_src_reg;
802801
}
803802
/* remember insn offset, so we can copy BTF ID and FD later */

0 commit comments

Comments
 (0)