Re: [PATCHv3 bpf-next 07/26] libbpf: Move elf_find_func_offset* functions to elf object

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

 



On Tue, Jul 11, 2023 at 2:05 AM Jiri Olsa <olsajiri@xxxxxxxxx> wrote:
>
> On Thu, Jul 06, 2023 at 04:02:22PM -0700, Andrii Nakryiko wrote:
> > On Fri, Jun 30, 2023 at 1:35 AM Jiri Olsa <jolsa@xxxxxxxxxx> wrote:
> > >
> > > Adding new elf object that will contain elf related functions.
> > > There's no functional change.
> > >
> > > Suggested-by: Andrii Nakryiko <andrii@xxxxxxxxxx>
> > > Signed-off-by: Jiri Olsa <jolsa@xxxxxxxxxx>
> > > ---
> > >  tools/lib/bpf/Build        |   2 +-
> > >  tools/lib/bpf/elf.c        | 198 +++++++++++++++++++++++++++++++++++++
> > >  tools/lib/bpf/libbpf.c     | 186 +---------------------------------
> > >  tools/lib/bpf/libbpf_elf.h |  11 +++
> > >  4 files changed, 211 insertions(+), 186 deletions(-)
> > >  create mode 100644 tools/lib/bpf/elf.c
> > >  create mode 100644 tools/lib/bpf/libbpf_elf.h
> > >
> >
> > [...]
> >
> > > diff --git a/tools/lib/bpf/libbpf_elf.h b/tools/lib/bpf/libbpf_elf.h
> > > new file mode 100644
> > > index 000000000000..1b652220fabf
> > > --- /dev/null
> > > +++ b/tools/lib/bpf/libbpf_elf.h
> > > @@ -0,0 +1,11 @@
> > > +/* SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) */
> > > +
> > > +#ifndef __LIBBPF_LIBBPF_ELF_H
> > > +#define __LIBBPF_LIBBPF_ELF_H
> > > +
> > > +#include <libelf.h>
> > > +
> > > +long elf_find_func_offset(Elf *elf, const char *binary_path, const char *name);
> > > +long elf_find_func_offset_from_file(const char *binary_path, const char *name);
> > > +
> > > +#endif /* *__LIBBPF_LIBBPF_ELF_H */
> >
> > we have libbpf_internal.h, let's put all this there for now, it's
> > already all the internal stuff together, I don't know if separate
> > header with few functions gives us much
>
> there's more functions coming later in the patchset
>
>         struct elf_fd {
>                 Elf *elf;
>                 int fd;
>         };
>
>         int elf_open(const char *binary_path, struct elf_fd *elf_fd);
>         void elf_close(struct elf_fd *elf_fd);
>
>         int elf_resolve_syms_offsets(const char *binary_path, int cnt,
>                                      const char **syms, unsigned long **poffsets);
>
>         int elf_resolve_pattern_offsets(const char *binary_path, const char *pattern,
>                                          unsigned long **poffsets, size_t *pcnt);
>
>
> and there's probably more elf helpers to eventually move in:
>
>         libbpf.c:static const char *elf_sym_str(const struct bpf_object *obj, size_t off);
>         libbpf.c:static const char *elf_sec_str(const struct bpf_object *obj, size_t off);
>         libbpf.c:static Elf_Scn *elf_sec_by_idx(const struct bpf_object *obj, size_t idx);
>         libbpf.c:static Elf_Scn *elf_sec_by_name(const struct bpf_object *obj, const char *name);
>         libbpf.c:static Elf64_Shdr *elf_sec_hdr(const struct bpf_object *obj, Elf_Scn *scn);
>         libbpf.c:static const char *elf_sec_name(const struct bpf_object *obj, Elf_Scn *scn);
>         libbpf.c:static Elf_Data *elf_sec_data(const struct bpf_object *obj, Elf_Scn *scn);
>         libbpf.c:static Elf64_Sym *elf_sym_by_idx(const struct bpf_object *obj, size_t idx);
>         libbpf.c:static Elf64_Rel *elf_rel_by_idx(Elf_Data *data, size_t idx);
>

yep, I was anticipating that these will move as well. But I think it's
fine if they all stay in libbpf_internal.h, IMO. I'd rather not have
many small internal header for no good reason (like we have
str_error.h right now, with a single func declaration)

>         usdt.c:static int find_elf_sec_by_name(Elf *elf, const char *sec_name, GElf_Shdr *shdr, Elf_Scn **scn)
>
>         'struct elf_seg' stuff
>
>         usdt.c:static int cmp_elf_segs(const void *_a, const void *_b)
>         usdt.c:static int parse_elf_segs(Elf *elf, const char *path, struct elf_seg **segs, size_t *seg_cnt)
>         usdt.c:static int parse_vma_segs(int pid, const char *lib_path, struct elf_seg **segs, size_t *seg_cnt)
>         usdt.c:static struct elf_seg *find_elf_seg(struct elf_seg *segs, size_t seg_cnt, long virtaddr)
>         usdt.c:static struct elf_seg *find_vma_seg(struct elf_seg *segs, size_t seg_cnt, long offset)
>
>
> but I can add the new header file later in follow up changes when
> we have more elf functions in

see above, I don't think we should, let's stick to libbpf_internal.h for now

>
> jirka





[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