All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eduard Zateev <hackerowskiy@gmail.com>
To: bpf@vger.kernel.org
Cc: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org,
	eddyz87@gmail.com, memxor@gmail.com, martin.lau@linux.dev,
	song@kernel.org, yonghong.song@linux.dev, jolsa@kernel.org,
	emil@etsalapis.com, ihor.solodrai@linux.dev, shuah@kernel.org,
	linux-kselftest@vger.kernel.org,
	Eduard Zateev <hackerowskiy@gmail.com>
Subject: [PATCH] libbpf: fix symbol resolution without .symtab
Date: Fri, 23 Oct 2026 16:10:40 +0200	[thread overview]
Message-ID: <20261023141040.249597-1-hackerowskiy@gmail.com> (raw)

When a binary has .dynsym but no .symtab, elf_sym_iter_new() returns -ENOENT for the optional table. Keep checking the other table and clear that error; otherwise successful dynamic-symbol lookups are reported as failures.

Add a regression selftest for a stripped shared object and verify that unresolved symbols still fail.

Link: https://github.com/libbpf/libbpf/issues/953
Signed-off-by: Eduard Zateev <hackerowskiy@gmail.com>
---
 tools/lib/bpf/elf.c                           |  5 ++-
 tools/testing/selftests/bpf/Makefile          |  7 +++-
 .../bpf/prog_tests/uprobe_multi_test.c        | 37 +++++++++++++++++++
 .../selftests/bpf/uprobe_multi_stripped.c     |  7 ++++
 4 files changed, 54 insertions(+), 2 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/uprobe_multi_stripped.c

diff --git a/tools/lib/bpf/elf.c b/tools/lib/bpf/elf.c
index 700c3911a..76baaf778 100644
--- a/tools/lib/bpf/elf.c
+++ b/tools/lib/bpf/elf.c
@@ -438,8 +438,11 @@ int elf_resolve_syms_offsets(const char *binary_path, int cnt,
 		struct elf_sym *sym;
 
 		err = elf_sym_iter_new(&iter, elf_fd.elf, binary_path, sh_types[i], st_type);
-		if (err == -ENOENT)
+		if (err == -ENOENT) {
+			/* A missing symbol table is OK; check the other one. */
+			err = 0;
 			continue;
+		}
 		if (err)
 			goto out;
 
diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
index 1e4af62e8..4125133d4 100644
--- a/tools/testing/selftests/bpf/Makefile
+++ b/tools/testing/selftests/bpf/Makefile
@@ -61,7 +61,8 @@ TEST_GEN_PROGS_EXTENDED = \
 	xdp_synproxy \
 	xskxceiver
 
-TEST_GEN_FILES += $(TEST_KMODS) liburandom_read.so urandom_read sign-file uprobe_multi
+TEST_GEN_FILES += $(TEST_KMODS) liburandom_read.so urandom_read sign-file uprobe_multi \
+	uprobe_multi_stripped.so
 
 ifneq ($(V),1)
 submake_extras := feature_display=0
@@ -666,6 +667,10 @@ $(OUTPUT)/uprobe_multi: uprobe_multi.c uprobe_multi.ld
 	$(Q)$(CC) $(CFLAGS) -Wl,-T,uprobe_multi.ld -O0 $(LDFLAGS) 	\
 		$(filter-out %.ld,$^) $(LDLIBS) -o $@
 
+$(OUTPUT)/uprobe_multi_stripped.so: uprobe_multi_stripped.c
+	$(call msg,BINARY,,$@)
+	$(Q)$(CC) $(CFLAGS) -fPIC -shared -Wl,-s $(LDFLAGS) $< -o $@
+
 EXTRA_CLEAN := $(SCRATCH_DIR) $(HOST_SCRATCH_DIR)			\
 	prog_tests/tests.h map_tests/tests.h verifier/tests.h		\
 	feature bpftool $(TEST_KMOD_TARGETS)				\
diff --git a/tools/testing/selftests/bpf/prog_tests/uprobe_multi_test.c b/tools/testing/selftests/bpf/prog_tests/uprobe_multi_test.c
index f0baf5738..340e3b55c 100644
--- a/tools/testing/selftests/bpf/prog_tests/uprobe_multi_test.c
+++ b/tools/testing/selftests/bpf/prog_tests/uprobe_multi_test.c
@@ -374,6 +374,41 @@ static void test_attach_api_syms(void)
 	test_attach_api("/proc/self/exe", NULL, &opts);
 }
 
+static void test_attach_api_syms_stripped(void)
+{
+	LIBBPF_OPTS(bpf_uprobe_multi_opts, opts);
+	const char *syms[] = { "uprobe_multi_stripped_func" };
+	struct uprobe_multi *skel = NULL;
+	struct bpf_link *link = NULL;
+
+	opts.syms = syms;
+	opts.cnt = ARRAY_SIZE(syms);
+
+	skel = uprobe_multi__open_and_load();
+	if (!ASSERT_OK_PTR(skel, "uprobe_multi__open_and_load"))
+		return;
+
+	link = bpf_program__attach_uprobe_multi(skel->progs.uprobe, -1,
+						"./uprobe_multi_stripped.so", NULL, &opts);
+	if (!ASSERT_OK_PTR(link, "attach_uprobe_multi_stripped")) {
+		link = NULL;
+		goto cleanup;
+	}
+	bpf_link__destroy(link);
+	link = NULL;
+
+	/* A missing symbol must still be reported as an error. */
+	syms[0] = "uprobe_multi_missing_func";
+	link = bpf_program__attach_uprobe_multi(skel->progs.uprobe, -1,
+						"./uprobe_multi_stripped.so", NULL, &opts);
+	if (!ASSERT_ERR_PTR(link, "attach_uprobe_multi_missing_symbol"))
+		bpf_link__destroy(link);
+	link = NULL;
+
+cleanup:
+	uprobe_multi__destroy(skel);
+}
+
 static void test_attach_api_fails(void)
 {
 	LIBBPF_OPTS(bpf_link_create_opts, opts);
@@ -1442,6 +1477,8 @@ void test_uprobe_multi_test(void)
 		test_attach_api_pattern();
 	if (test__start_subtest("attach_api_syms"))
 		test_attach_api_syms();
+	if (test__start_subtest("attach_api_syms_stripped"))
+		test_attach_api_syms_stripped();
 	if (test__start_subtest("link_api"))
 		test_link_api();
 	if (test__start_subtest("link_api_path_fd"))
diff --git a/tools/testing/selftests/bpf/uprobe_multi_stripped.c b/tools/testing/selftests/bpf/uprobe_multi_stripped.c
new file mode 100644
index 000000000..9bdf7fb9b
--- /dev/null
+++ b/tools/testing/selftests/bpf/uprobe_multi_stripped.c
@@ -0,0 +1,7 @@
+// SPDX-License-Identifier: GPL-2.0
+
+__attribute__((noinline, visibility("default")))
+int uprobe_multi_stripped_func(void)
+{
+	return 42;
+}
-- 
2.55.0


             reply	other threads:[~2026-10-23 14:10 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-23 14:10 Eduard Zateev [this message]
2026-10-23 14:28 ` [PATCH] libbpf: fix symbol resolution without .symtab sashiko-bot
2026-10-23 15:59 ` Alexei Starovoitov

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=20261023141040.249597-1-hackerowskiy@gmail.com \
    --to=hackerowskiy@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=emil@etsalapis.com \
    --cc=ihor.solodrai@linux.dev \
    --cc=jolsa@kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=memxor@gmail.com \
    --cc=shuah@kernel.org \
    --cc=song@kernel.org \
    --cc=yonghong.song@linux.dev \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.