libbpf: Add typeless ksym support to gen_loader
authorKumar Kartikeya Dwivedi <memxor@gmail.com>
Thu, 28 Oct 2021 06:34:55 +0000 (12:04 +0530)
committerAlexei Starovoitov <ast@kernel.org>
Thu, 28 Oct 2021 23:30:06 +0000 (16:30 -0700)
commitc24941cd3766b6de682dbe6809bd6af12271ab5b
tree986c39d2900886f2dc7b7eb2366dc946020fd548
parentd6aef08a872b9e23eecc92d0e92393473b13c497
libbpf: Add typeless ksym support to gen_loader

This uses the bpf_kallsyms_lookup_name helper added in previous patches
to relocate typeless ksyms. The return value ENOENT can be ignored, and
the value written to 'res' can be directly stored to the insn, as it is
overwritten to 0 on lookup failure. For repeating symbols, we can simply
copy the previously populated bpf_insn.

Also, we need to take care to not close fds for typeless ksym_desc, so
reuse the 'off' member's space to add a marker for typeless ksym and use
that to skip them in cleanup_relos.

We add a emit_ksym_relo_log helper that avoids duplicating common
logging instructions between typeless and weak ksym (for future commit).

Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20211028063501.2239335-3-memxor@gmail.com
tools/lib/bpf/bpf_gen_internal.h
tools/lib/bpf/gen_loader.c
tools/lib/bpf/libbpf.c