On Tue, Nov 30, 2021 at 3:06 PM Alexei Starovoitov <alexei.starovoitov@xxxxxxxxx> wrote: > > On Mon, Nov 29, 2021 at 8:10 PM Andrii Nakryiko > <andrii.nakryiko@xxxxxxxxx> wrote: > > > > oh, I thought you added those fields initially and forgot to delete or > > something, didn't notice that you are just "opting them out" for > > __KERNEL__. I think libbpf code doesn't strictly need this, here's the > > diff that completely removes their use, it's pretty straightforward > > and minimal, so maybe instead of #ifdef'ing let's just do that? > > > > diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c > > index b59fede08ba7..95fa57eea289 100644 > > --- a/tools/lib/bpf/libbpf.c > > +++ b/tools/lib/bpf/libbpf.c > > @@ -5179,15 +5179,18 @@ static int bpf_core_add_cands(struct > > bpf_core_cand *local_cand, > > struct bpf_core_cand_list *cands) > > { > > struct bpf_core_cand *new_cands, *cand; > > - const struct btf_type *t; > > - const char *targ_name; > > + const struct btf_type *t, *local_t; > > + const char *targ_name, *local_name; > > size_t targ_essent_len; > > int n, i; > > > > + local_t = btf__type_by_id(local_cand->btf, local_cand->id); > > + local_name = btf__str_by_offset(local_cand->btf, local_t->name_off); > > + > > n = btf__type_cnt(targ_btf); > > for (i = targ_start_id; i < n; i++) { > > t = btf__type_by_id(targ_btf, i); > > - if (btf_kind(t) != btf_kind(local_cand->t)) > > + if (btf_kind(t) != btf_kind(local_t)) > > continue; > > > > targ_name = btf__name_by_offset(targ_btf, t->name_off); > > @@ -5198,12 +5201,12 @@ static int bpf_core_add_cands(struct > > bpf_core_cand *local_cand, > > if (targ_essent_len != local_essent_len) > > continue; > > > > - if (strncmp(local_cand->name, targ_name, local_essent_len) != 0) > > + if (strncmp(local_name, targ_name, local_essent_len) != 0) > > continue; > > > > pr_debug("CO-RE relocating [%d] %s %s: found target candidate > > [%d] %s %s in [%s]\n", > > - local_cand->id, btf_kind_str(local_cand->t), > > - local_cand->name, i, btf_kind_str(t), targ_name, > > + local_cand->id, btf_kind_str(local_t), > > + local_name, i, btf_kind_str(t), targ_name, > > targ_btf_name); > > new_cands = libbpf_reallocarray(cands->cands, cands->len + 1, > > sizeof(*cands->cands)); > > @@ -5212,8 +5215,6 @@ static int bpf_core_add_cands(struct > > bpf_core_cand *local_cand, > > > > cand = &new_cands[cands->len]; > > cand->btf = targ_btf; > > - cand->t = t; > > - cand->name = targ_name; > > cand->id = i; > > > > cands->cands = new_cands; > > @@ -5320,18 +5321,20 @@ bpf_core_find_cands(struct bpf_object *obj, > > const struct btf *local_btf, __u32 l > > struct bpf_core_cand local_cand = {}; > > struct bpf_core_cand_list *cands; > > const struct btf *main_btf; > > + const struct btf_type *local_t; > > + const char *local_name; > > size_t local_essent_len; > > int err, i; > > > > local_cand.btf = local_btf; > > - local_cand.t = btf__type_by_id(local_btf, local_type_id); > > - if (!local_cand.t) > > + local_t = btf__type_by_id(local_btf, local_type_id); > > + if (!local_t) > > return ERR_PTR(-EINVAL); > > Heh. Looks like you only compile-tested it :) of course :) > I was surprised that CO-RE in the kernel was working, > but libbpf CO-RE didn't :) > Thankfully the fix was simple: > > diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c > index 24d1cbc30084..1341ce539662 100644 > --- a/tools/lib/bpf/libbpf.c > +++ b/tools/lib/bpf/libbpf.c > @@ -5333,6 +5333,7 @@ bpf_core_find_cands(struct bpf_object *obj, > const struct btf *local_btf, __u32 l > int err, i; > > local_cand.btf = local_btf; > + local_cand.id = local_type_id; fascinating, we didn't really use id because we just had type directly, nice find, sorry about that > local_t = btf__type_by_id(local_btf, local_type_id); > > Just fyi.