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/Build b/tools/lib/bpf/Build > index b8b0a6369363..2d0c282c8588 100644 > --- a/tools/lib/bpf/Build > +++ b/tools/lib/bpf/Build > @@ -1,4 +1,4 @@ > libbpf-y := libbpf.o bpf.o nlattr.o btf.o libbpf_errno.o str_error.o \ > netlink.o bpf_prog_linfo.o libbpf_probes.o hashmap.o \ > btf_dump.o ringbuf.o strset.o linker.o gen_loader.o relo_core.o \ > - usdt.o zip.o > + usdt.o zip.o elf.o > diff --git a/tools/lib/bpf/elf.c b/tools/lib/bpf/elf.c > new file mode 100644 > index 000000000000..2b62b4af28ce > --- /dev/null > +++ b/tools/lib/bpf/elf.c > @@ -0,0 +1,198 @@ > +// SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) > + > +#include <libelf.h> > +#include <gelf.h> > +#include <fcntl.h> > +#include <linux/kernel.h> do you know why we need linux/kernel.h include? is it to get __u32 and other typedefs? > + > +#include "libbpf_elf.h" > +#include "libbpf_internal.h" > +#include "str_error.h" > + > +#define STRERR_BUFSIZE 128 > + [...]