> On Oct 14, 2021, at 1:56 PM, Kumar Kartikeya Dwivedi <memxor@xxxxxxxxx> wrote: > > This extends existing ksym relocation code to also support relocating > weak ksyms. Care needs to be taken to zero out the src_reg (currently > BPF_PSEUOD_BTF_ID, always set for gen_loader by bpf_object__relocate_data) > when the BTF ID lookup fails at runtime. This is not a problem for > libbpf as it only sets ext->is_set when BTF ID lookup succeeds (and only > proceeds in case of failure if ext->is_weak, leading to src_reg > remaining as 0 for weak unresolved ksym). > > A pattern similar to emit_relo_kfunc_btf is followed of first storing > the default values and then jumping over actual stores in case of an > error. For src_reg adjustment, we also need to perform it when copying > the populated instruction, so depending on if copied insn[0].imm is 0 or > not, we decide to jump over the adjustment. > > We cannot reach that point unless the ksym was weak and resolved and > zeroed out, as the emit_check_err will cause us to jump to cleanup > label, so we do not need to recheck whether the ksym is weak before > doing the adjustment after copying BTF ID and BTF FD. > > This is consistent with how libbpf relocates weak ksym. Logging > statements are added to show the relocation result and aid debugging. > > Signed-off-by: Kumar Kartikeya Dwivedi <memxor@xxxxxxxxx> Acked-by: Song Liu <songliubraving@xxxxxx>