aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKumar Kartikeya Dwivedi <memxor@gmail.com>2021-11-23 05:27:33 +0530
committerAndrii Nakryiko <andrii.nakryiko@gmail.com>2021-12-10 14:03:13 -0800
commitc4da8092ccdf420aaa3a179c59c6c8ee4cbe483b (patch)
treefdc5a6c2151dce65d73f22de589e08dec66f4f47 /src
parentb2b45a3131295ea7d1fc2cd3aeed4cdacadb8126 (diff)
downloadlibbpf-c4da8092ccdf420aaa3a179c59c6c8ee4cbe483b.tar.gz
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 <ast@kernel.org> Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com> Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Acked-by: Song Liu <songliubraving@fb.com> Link: https://lore.kernel.org/bpf/20211122235733.634914-4-memxor@gmail.com
Diffstat (limited to 'src')
-rw-r--r--src/gen_loader.c5
1 files changed, 2 insertions, 3 deletions
diff --git a/src/gen_loader.c b/src/gen_loader.c
index 3fe45f1..f62d616 100644
--- a/src/gen_loader.c
+++ b/src/gen_loader.c
@@ -808,9 +808,8 @@ static void emit_relo_ksym_btf(struct bpf_gen *gen, struct ksym_relo_desc *relo,
kdesc->insn + offsetof(struct bpf_insn, imm));
move_blob2blob(gen, insn + sizeof(struct bpf_insn) + offsetof(struct bpf_insn, imm), 4,
kdesc->insn + sizeof(struct bpf_insn) + offsetof(struct bpf_insn, imm));
- emit(gen, BPF_LDX_MEM(BPF_W, BPF_REG_9, BPF_REG_8, offsetof(struct bpf_insn, imm)));
- /* jump over src_reg adjustment if imm is not 0 */
- emit(gen, BPF_JMP_IMM(BPF_JNE, BPF_REG_9, 0, 3));
+ /* jump over src_reg adjustment if imm is not 0, reuse BPF_REG_0 from move_blob2blob */
+ emit(gen, BPF_JMP_IMM(BPF_JNE, BPF_REG_0, 0, 3));
goto clear_src_reg;
}
/* remember insn offset, so we can copy BTF ID and FD later */