From: "Mauricio Vásquez Bernal" <mauricio@kinvolk.io> To: Quentin Monnet <quentin@isovalent.com> Cc: Networking <netdev@vger.kernel.org>, bpf <bpf@vger.kernel.org>, Alexei Starovoitov <ast@kernel.org>, Daniel Borkmann <daniel@iogearbox.net>, Andrii Nakryiko <andrii@kernel.org>, Rafael David Tinoco <rafaeldtinoco@gmail.com>, Lorenzo Fontana <lorenzo.fontana@elastic.co>, Leonardo Di Donato <leonardo.didonato@elastic.co> Subject: Re: [PATCH bpf-next v7 4/7] bpftool: Implement "gen min_core_btf" logic Date: Fri, 18 Feb 2022 14:43:53 -0500 [thread overview] Message-ID: <CAHap4zu255wb+e6_rY9SwWtu+GiedZjnSitOCWksN98jtBu=BQ@mail.gmail.com> (raw) In-Reply-To: <3bf2bd49-9f2d-a2df-5536-bc0dde70a83b@isovalent.com> On Fri, Feb 18, 2022 at 11:20 AM Quentin Monnet <quentin@isovalent.com> wrote: > > 2022-02-15 17:58 UTC-0500 ~ Mauricio Vásquez <mauricio@kinvolk.io> > > This commit implements the logic for the gen min_core_btf command. > > Specifically, it implements the following functions: > > > > - minimize_btf(): receives the path of a source and destination BTF > > files and a list of BPF objects. This function records the relocations > > for all objects and then generates the BTF file by calling > > btfgen_get_btf() (implemented in the following commit). > > > > - btfgen_record_obj(): loads the BTF and BTF.ext sections of the BPF > > objects and loops through all CO-RE relocations. It uses > > bpf_core_calc_relo_insn() from libbpf and passes the target spec to > > btfgen_record_reloc(), that calls one of the following functions > > depending on the relocation kind. > > > > - btfgen_record_field_relo(): uses the target specification to mark all > > the types that are involved in a field-based CO-RE relocation. In this > > case types resolved and marked recursively using btfgen_mark_type(). > > Only the struct and union members (and their types) involved in the > > relocation are marked to optimize the size of the generated BTF file. > > > > - btfgen_record_type_relo(): marks the types involved in a type-based > > CO-RE relocation. In this case no members for the struct and union types > > are marked as libbpf doesn't use them while performing this kind of > > relocation. Pointed types are marked as they are used by libbpf in this > > case. > > > > - btfgen_record_enumval_relo(): marks the whole enum type for enum-based > > relocations. > > > > Signed-off-by: Mauricio Vásquez <mauricio@kinvolk.io> > > Signed-off-by: Rafael David Tinoco <rafael.tinoco@aquasec.com> > > Signed-off-by: Lorenzo Fontana <lorenzo.fontana@elastic.co> > > Signed-off-by: Leonardo Di Donato <leonardo.didonato@elastic.co> > > --- > > tools/bpf/bpftool/Makefile | 8 +- > > tools/bpf/bpftool/gen.c | 455 ++++++++++++++++++++++++++++++++++++- > > 2 files changed, 457 insertions(+), 6 deletions(-) > > > > diff --git a/tools/bpf/bpftool/Makefile b/tools/bpf/bpftool/Makefile > > index 94b2c2f4ad43..a137db96bd56 100644 > > --- a/tools/bpf/bpftool/Makefile > > +++ b/tools/bpf/bpftool/Makefile > > @@ -34,10 +34,10 @@ LIBBPF_BOOTSTRAP_INCLUDE := $(LIBBPF_BOOTSTRAP_DESTDIR)/include > > LIBBPF_BOOTSTRAP_HDRS_DIR := $(LIBBPF_BOOTSTRAP_INCLUDE)/bpf > > LIBBPF_BOOTSTRAP := $(LIBBPF_BOOTSTRAP_OUTPUT)libbpf.a > > > > -# We need to copy hashmap.h and nlattr.h which is not otherwise exported by > > -# libbpf, but still required by bpftool. > > -LIBBPF_INTERNAL_HDRS := $(addprefix $(LIBBPF_HDRS_DIR)/,hashmap.h nlattr.h) > > -LIBBPF_BOOTSTRAP_INTERNAL_HDRS := $(addprefix $(LIBBPF_BOOTSTRAP_HDRS_DIR)/,hashmap.h) > > +# We need to copy hashmap.h, nlattr.h, relo_core.h and libbpf_internal.h > > +# which are not otherwise exported by libbpf, but still required by bpftool. > > +LIBBPF_INTERNAL_HDRS := $(addprefix $(LIBBPF_HDRS_DIR)/,hashmap.h nlattr.h relo_core.h libbpf_internal.h) > > +LIBBPF_BOOTSTRAP_INTERNAL_HDRS := $(addprefix $(LIBBPF_BOOTSTRAP_HDRS_DIR)/,hashmap.h relo_core.h libbpf_internal.h) > > > > $(LIBBPF_OUTPUT) $(BOOTSTRAP_OUTPUT) $(LIBBPF_BOOTSTRAP_OUTPUT) $(LIBBPF_HDRS_DIR) $(LIBBPF_BOOTSTRAP_HDRS_DIR): > > $(QUIET_MKDIR)mkdir -p $@ > > diff --git a/tools/bpf/bpftool/gen.c b/tools/bpf/bpftool/gen.c > > index 8e066c747691..806001020841 100644 > > --- a/tools/bpf/bpftool/gen.c > > +++ b/tools/bpf/bpftool/gen.c > > @@ -14,6 +14,7 @@ > > #include <unistd.h> > > #include <bpf/bpf.h> > > #include <bpf/libbpf.h> > > +#include <bpf/libbpf_internal.h> > > #include <sys/types.h> > > #include <sys/stat.h> > > #include <sys/mman.h> > > Mauricio, did you try this patch on a system with an old Glibc (< 2.26) > by any chance? Haven't tried yet but I expect this might break bpftool's > build when COMPAT_NEED_REALLOCARRAY is set, because in that case gen.c > pulls <bpf/libbpf_internal.h>, and then <tools/libc_compat.h> (through > main.h). And libc_compat.h defines reallocarray(), which > libbpf_internal.h poisons with a GCC pragma. > I just tried on Ubuntu 16.04 with Glibc 2.23 and got the error you mentioned. > At least this is what I observe when trying to add your patches to the > kernel mirror, where reallocarray() is redefined unconditionally. I'm > trying to figure out if we should fix this mirror-side, or kernel-side. > (I suppose we still need this compatibility layer, Ubuntu 16.04 seems to > use Glibc 2.23). > I suppose this should be fixed kernel-side, I don't think it's a particular problem with the mirror. What about only including `<tools/libc_compat.h>` in the places where reallocarray() is used: prog.c and xlated_dumper.c?
next prev parent reply other threads:[~2022-02-18 19:44 UTC|newest] Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-02-15 22:58 [PATCH bpf-next v7 0/7] libbpf: Implement BTFGen Mauricio Vásquez 2022-02-15 22:58 ` [PATCH bpf-next v7 1/7] libbpf: split bpf_core_apply_relo() Mauricio Vásquez 2022-02-16 1:52 ` Alexei Starovoitov 2022-02-15 22:58 ` [PATCH bpf-next v7 2/7] libbpf: Expose bpf_core_{add,free}_cands() to bpftool Mauricio Vásquez 2022-02-15 22:58 ` [PATCH bpf-next v7 3/7] bpftool: Add gen min_core_btf command Mauricio Vásquez 2022-02-15 22:58 ` [PATCH bpf-next v7 4/7] bpftool: Implement "gen min_core_btf" logic Mauricio Vásquez 2022-02-18 16:20 ` Quentin Monnet 2022-02-18 19:43 ` Mauricio Vásquez Bernal [this message] 2022-02-18 19:48 ` Andrii Nakryiko 2022-02-18 19:52 ` Quentin Monnet 2022-02-15 22:58 ` [PATCH bpf-next v7 5/7] bpftool: Implement btfgen_get_btf() Mauricio Vásquez 2022-02-16 18:20 ` Andrii Nakryiko 2022-02-15 22:58 ` [PATCH bpf-next v7 6/7] bpftool: gen min_core_btf explanation and examples Mauricio Vásquez 2022-02-16 18:20 ` Andrii Nakryiko 2022-02-15 22:58 ` [PATCH bpf-next v7 7/7] selftests/bpf: Test "bpftool gen min_core_btf" Mauricio Vásquez 2022-02-16 18:20 ` Andrii Nakryiko 2022-02-16 18:20 ` [PATCH bpf-next v7 0/7] libbpf: Implement BTFGen Andrii Nakryiko 2022-02-17 22:07 ` Mauricio Vásquez Bernal 2022-02-17 22:12 ` Andrii Nakryiko 2022-02-16 18:30 ` patchwork-bot+netdevbpf
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to='CAHap4zu255wb+e6_rY9SwWtu+GiedZjnSitOCWksN98jtBu=BQ@mail.gmail.com' \ --to=mauricio@kinvolk.io \ --cc=andrii@kernel.org \ --cc=ast@kernel.org \ --cc=bpf@vger.kernel.org \ --cc=daniel@iogearbox.net \ --cc=leonardo.didonato@elastic.co \ --cc=lorenzo.fontana@elastic.co \ --cc=netdev@vger.kernel.org \ --cc=quentin@isovalent.com \ --cc=rafaeldtinoco@gmail.com \ --subject='Re: [PATCH bpf-next v7 4/7] bpftool: Implement "gen min_core_btf" logic' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).