Re: [PATCH bpf-next v3 08/11] libbpf: support subprog address relocation

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Feb 25, 2021 at 1:35 AM Yonghong Song <yhs@xxxxxx> wrote:
>
> A new relocation RELO_SUBPROG_ADDR is added to capture
> subprog addresses loaded with ld_imm64 insns. Such ld_imm64
> insns are marked with BPF_PSEUDO_FUNC and will be passed to
> kernel. For bpf_for_each_map_elem() case, kernel will
> check that the to-be-used subprog address must be a static
> function and replace it with proper actual jited func address.
>
> Signed-off-by: Yonghong Song <yhs@xxxxxx>
> ---
>  tools/lib/bpf/libbpf.c | 64 ++++++++++++++++++++++++++++++++++++++++--
>  1 file changed, 61 insertions(+), 3 deletions(-)
>

LGTM. I'll still need to relax it a bit more for static functions, but
it can come as part of static linker work.

Acked-by: Andrii Nakryiko <andrii@xxxxxxxxxx>

[...]
> +static bool sym_is_subprog(const GElf_Sym *sym, int text_shndx)
> +{
> +       int bind = GELF_ST_BIND(sym->st_info);
> +       int type = GELF_ST_TYPE(sym->st_info);
> +
> +       /* in .text section */
> +       if (sym->st_shndx != text_shndx)
> +               return false;
> +
> +       /* local function */
> +       if (bind == STB_LOCAL && type == STT_SECTION)
> +               return true;
> +
> +       /* global function */
> +       return bind == STB_GLOBAL && type == STT_FUNC;

theoretically STT_FUNC could be STB_LOCAL here, though Clang doesn't
emit it that way today. It will be easy to fix later, though. Just
mentioning, because I intend to have STB_LOCAL + STT_FUNC relocations
with BPF static linker.

> +}
> +
>  static int find_extern_btf_id(const struct btf *btf, const char *ext_name)
>  {
>         const struct btf_type *t;

[...]



[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux