From: Geyslan Gregório libbpf reads /proc/kallsyms when an object has a typeless ksym, and kallsyms_cb() marks every variable ksym it finds there as set, typed ones too. Typed ksyms are resolved through kernel BTF, and the relocation of a typed ksym that is set uses its BTF id only. A weak typed variable that kernel BTF does not have is left unresolved by bpf_object__resolve_ksym_var_btf_id(). If kallsyms has a symbol of that name, the extern is set all the same, and it is relocated as BPF_PSEUDO_BTF_ID with id 0. The verifier rejects the program: pseudo btf_id 0 in ldimm64 isn't KIND_VAR or KIND_FUNC For example, on a kernel whose BTF describes per-CPU variables only: extern const struct file_operations bpf_link_fops __ksym __weak; extern const void bpf_prog_active __ksym; Have kallsyms_cb() skip typed ksyms. A function ksym always has a type, so this replaces the check that skipped functions. A weak typed variable missing from kernel BTF now reads as absent, as it already does in an object with no typeless ksym. Fixes: 2211c825e7b6 ("libbpf: Support weak typed ksyms.") Signed-off-by: Geyslan Gregório --- tools/lib/bpf/libbpf.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index 2b188e64e356..6fe0143ea959 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -9769,7 +9769,6 @@ static int kallsyms_cb(unsigned long long sym_addr, char sym_type, const char *sym_name, void *ctx) { struct bpf_object *obj = ctx; - const struct btf_type *t; struct extern_desc *ext; const char *res; @@ -9781,8 +9780,10 @@ static int kallsyms_cb(unsigned long long sym_addr, char sym_type, if (!ext || ext->type != EXT_KSYM) return 0; - t = btf__type_by_id(obj->btf, ext->btf_id); - if (!btf_is_var(t)) + /* Typed ksyms, variables and functions, are resolved through kernel + * BTF only. + */ + if (ext->ksym.type_id) return 0; if (ext->is_set && ext->ksym.addr != sym_addr) { -- 2.56.1