Re: [PATCH v4 bpf-next 03/11] libbpf: add btf__parse_opts() API for flexible BTF parsing

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

 



On Fri, May 17, 2024 at 3:23 AM Alan Maguire <alan.maguire@xxxxxxxxxx> wrote:
>
> Options cover existing parsing scenarios (ELF, raw, retrieving
> .BTF.ext) and also allow specification of the ELF section name
> containing BTF.  This will allow consumers to retrieve BTF from
> .BTF.base sections (BTF_BASE_ELF_SEC) also.
>
> Signed-off-by: Alan Maguire <alan.maguire@xxxxxxxxxx>
> ---
>  tools/lib/bpf/btf.c      | 49 +++++++++++++++++++++++++++-------------
>  tools/lib/bpf/btf.h      | 31 +++++++++++++++++++++++++
>  tools/lib/bpf/libbpf.map |  1 +
>  3 files changed, 65 insertions(+), 16 deletions(-)
>

[...]

> -static struct btf *btf_parse(const char *path, struct btf *base_btf, struct btf_ext **btf_ext)
> +struct btf *btf__parse_opts(const char *path, struct btf_parse_opts *opts)
>  {
> -       struct btf *btf;
> +       struct btf *btf, *base_btf;
> +       const char *btf_sec;
> +       struct btf_ext **btf_ext;
>         int err;
>
> +       if (!OPTS_VALID(opts, btf_parse_opts))
> +               return libbpf_err_ptr(-EINVAL);
> +       base_btf = OPTS_GET(opts, base_btf, NULL);
> +       btf_sec = OPTS_GET(opts, btf_sec, NULL);
> +       btf_ext = OPTS_GET(opts, btf_ext, NULL);
> +
>         if (btf_ext)
>                 *btf_ext = NULL;
> -
> -       btf = btf_parse_raw(path, base_btf);
> +       if (!btf_sec) {
> +               btf = btf_parse_raw(path, base_btf);
> +               err = libbpf_get_error(btf);

IS_ERR/PTR_ERR, btf_parse_raw is internal function, not a public API,
so we shouldn't be using libbpf_get_error() here

> +               if (!err)
> +                       return btf;
> +               if (err != -EPROTO)
> +                       return libbpf_err_ptr(err);
> +       }
> +       btf = btf_parse_elf(path, btf_sec ?: BTF_ELF_SEC, base_btf, btf_ext);
>         err = libbpf_get_error(btf);
> -       if (!err)
> -               return btf;
> -       if (err != -EPROTO)
> -               return ERR_PTR(err);
> -       return btf_parse_elf(path, base_btf, btf_ext);
> +       if (err)
> +               return libbpf_err_ptr(err);
> +       return btf;
>  }

[...]





[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