All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] libbpf: fix weak kfunc name suffix resolution for light skeletons
@ 2026-06-22 21:03 Siddharth Nayyar
  2026-06-22 21:17 ` sashiko-bot
  0 siblings, 1 reply; 3+ messages in thread
From: Siddharth Nayyar @ 2026-06-22 21:03 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Eduard Zingerman, Kumar Kartikeya Dwivedi, Martin KaFai Lau,
	Song Liu, Yonghong Song, Jiri Olsa, Emil Tsalapatis
  Cc: bpf, linux-kernel, Giuliano Procida, Matthias Maennich,
	Tiffany Yang, Neill Kapron, Siddharth Nayyar

When generating a light skeleton, libbpf currently records the
unstripped name (e.g., `func___compat`) of kfuncs into the external
symbol records.  However, the kernel's verifier strips suffixes and
expects the essential name to resolve `bpf_ksym_exists()` correctly.

This breaks backwards-compatibility fallback logic in light skeletons,
as the kernel fails to resolve the suffixed kfunc and evaluates
`bpf_ksym_exists()` to 0, falsely assuming the kfunc is absent.

Fix this by passing `ext->essent_name` when calling
`bpf_gen__record_extern()` for BTF_KIND_FUNC. For BTF_KIND_VAR, the
behavior is unchanged, preserving suffix compatibility.

Signed-off-by: Siddharth Nayyar <sidnayyar@google.com>
---
 tools/lib/bpf/libbpf.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 1368752aa13c..421bfd5e159d 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -8309,19 +8309,25 @@ static int bpf_program_record_relos(struct bpf_program *prog)
 		struct reloc_desc *relo = &prog->reloc_desc[i];
 		struct extern_desc *ext = &obj->externs[relo->ext_idx];
 		int kind;
+		const char *name;
 
 		switch (relo->type) {
 		case RELO_EXTERN_LD64:
 			if (ext->type != EXT_KSYM)
 				continue;
-			kind = btf_is_var(btf__type_by_id(obj->btf, ext->btf_id)) ?
-				BTF_KIND_VAR : BTF_KIND_FUNC;
-			bpf_gen__record_extern(obj->gen_loader, ext->name,
+			if (btf_is_var(btf__type_by_id(obj->btf, ext->btf_id))) {
+				kind = BTF_KIND_VAR;
+				name = ext->name;
+			} else {
+				kind = BTF_KIND_FUNC;
+				name = ext->essent_name ?: ext->name;
+			}
+			bpf_gen__record_extern(obj->gen_loader, name,
 					       ext->is_weak, !ext->ksym.type_id,
 					       true, kind, relo->insn_idx);
 			break;
 		case RELO_EXTERN_CALL:
-			bpf_gen__record_extern(obj->gen_loader, ext->name,
+			bpf_gen__record_extern(obj->gen_loader, ext->essent_name ?: ext->name,
 					       ext->is_weak, false, false, BTF_KIND_FUNC,
 					       relo->insn_idx);
 			break;

---
base-commit: e771677c937da5808f7b6c1f0e4a97ec1a84f8a8
change-id: 20260622-bpf-lskel-fixes-cafd1a83dec2

Best regards,
-- 
Siddharth Nayyar <sidnayyar@google.com>


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-06-22 22:10 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-22 21:03 [PATCH] libbpf: fix weak kfunc name suffix resolution for light skeletons Siddharth Nayyar
2026-06-22 21:17 ` sashiko-bot
2026-06-22 22:10   ` Sid Nayyar

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.