Message ID | b107f56787c89464ab52828b885e1a208312d20b.1646957399.git.delyank@fb.com (mailing list archive) |
---|---|
State | Superseded |
Delegated to: | BPF |
Headers | show |
Series | Subskeleton support for BPF libraries | expand |
On Thu, Mar 10, 2022 at 4:12 PM Delyan Kratunov <delyank@fb.com> wrote: > > Currently, libbpf considers a single routine in .text as a program. This > is particularly confusing when it comes to library objects - a single routine > meant to be used as an extern will instead be considered a bpf_program. > > This patch hides this compatibility behavior behind a libbpf_mode strict > mode flag. > > Signed-off-by: Delyan Kratunov <delyank@fb.com> > --- > tools/lib/bpf/libbpf.c | 7 +++++++ > tools/lib/bpf/libbpf_legacy.h | 6 ++++++ > 2 files changed, 13 insertions(+) > > diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c > index 43161fdd44bb..b6f11ce0d6bc 100644 > --- a/tools/lib/bpf/libbpf.c > +++ b/tools/lib/bpf/libbpf.c > @@ -3832,7 +3832,14 @@ static bool prog_is_subprog(const struct bpf_object *obj, > * .text programs are subprograms (even if they are not called from > * other programs), because libbpf never explicitly supported mixing > * SEC()-designated BPF programs and .text entry-point BPF programs. > + * > + * In libbpf 1.0 strict mode, we always consider .text > + * programs to be subprograms. > */ > + > + if (libbpf_mode & LIBBPF_STRICT_TEXT_ONLY_SUBPROGRAMS) > + return prog->sec_idx == obj->efile.text_shndx; > + > return prog->sec_idx == obj->efile.text_shndx && obj->nr_programs > 1; > } > > diff --git a/tools/lib/bpf/libbpf_legacy.h b/tools/lib/bpf/libbpf_legacy.h > index a283cf031665..388384ea97a7 100644 > --- a/tools/lib/bpf/libbpf_legacy.h > +++ b/tools/lib/bpf/libbpf_legacy.h > @@ -78,6 +78,12 @@ enum libbpf_strict_mode { > * in favor of BTF-defined map definitions in SEC(".maps"). > */ > LIBBPF_STRICT_MAP_DEFINITIONS = 0x20, > + /* > + * When enabled, always consider routines in the .text section to > + * be sub-programs. Previously, single routines in the .text section > + * would be considered a program on their own. > + */ > + LIBBPF_STRICT_TEXT_ONLY_SUBPROGRAMS = 0x40, We have LIBBPF_STRICT_SEC_NAME, we can probably just rely on that one. STRICT_SEC_NAME means (among other things) that there has to be SEC("abc"), so there can't be BPF program in .text section. We don't enforce that yet, but that's a separate thing. > > __LIBBPF_STRICT_LAST, > }; > -- > 2.34.1
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index 43161fdd44bb..b6f11ce0d6bc 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -3832,7 +3832,14 @@ static bool prog_is_subprog(const struct bpf_object *obj, * .text programs are subprograms (even if they are not called from * other programs), because libbpf never explicitly supported mixing * SEC()-designated BPF programs and .text entry-point BPF programs. + * + * In libbpf 1.0 strict mode, we always consider .text + * programs to be subprograms. */ + + if (libbpf_mode & LIBBPF_STRICT_TEXT_ONLY_SUBPROGRAMS) + return prog->sec_idx == obj->efile.text_shndx; + return prog->sec_idx == obj->efile.text_shndx && obj->nr_programs > 1; } diff --git a/tools/lib/bpf/libbpf_legacy.h b/tools/lib/bpf/libbpf_legacy.h index a283cf031665..388384ea97a7 100644 --- a/tools/lib/bpf/libbpf_legacy.h +++ b/tools/lib/bpf/libbpf_legacy.h @@ -78,6 +78,12 @@ enum libbpf_strict_mode { * in favor of BTF-defined map definitions in SEC(".maps"). */ LIBBPF_STRICT_MAP_DEFINITIONS = 0x20, + /* + * When enabled, always consider routines in the .text section to + * be sub-programs. Previously, single routines in the .text section + * would be considered a program on their own. + */ + LIBBPF_STRICT_TEXT_ONLY_SUBPROGRAMS = 0x40, __LIBBPF_STRICT_LAST, };
Currently, libbpf considers a single routine in .text as a program. This is particularly confusing when it comes to library objects - a single routine meant to be used as an extern will instead be considered a bpf_program. This patch hides this compatibility behavior behind a libbpf_mode strict mode flag. Signed-off-by: Delyan Kratunov <delyank@fb.com> --- tools/lib/bpf/libbpf.c | 7 +++++++ tools/lib/bpf/libbpf_legacy.h | 6 ++++++ 2 files changed, 13 insertions(+)