Build liburandom_read_stripped.so, a copy of liburandom_read.so without .symtab, and add a uprobe_multi_test subtest that resolves two of its functions with elf_resolve_syms_offsets(). Without the previous patch the call fails with -ENOENT. Written with the help of Claude Code, an AI coding assistant, and reviewed by the author. Signed-off-by: Mehmet Rıfat Özkal --- tools/testing/selftests/bpf/Makefile | 12 +++++++-- .../bpf/prog_tests/uprobe_multi_test.c | 25 +++++++++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile index c99e0f623..9188065af 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 liburandom_read_stripped.so \ + urandom_read sign-file uprobe_multi ifneq ($(V),1) submake_extras := feature_display=0 @@ -194,6 +195,11 @@ $(OUTPUT)/liburandom_read.so: urandom_read_lib1.c urandom_read_lib2.c liburandom -Wl,--version-script=liburandom_read.map \ -fPIC -shared -o $@ +# The same library without .symtab, only .dynsym, as distributions ship them. +$(OUTPUT)/liburandom_read_stripped.so: $(OUTPUT)/liburandom_read.so + $(call msg,STRIP,,$@) + $(Q)$(LLVM_STRIP) --strip-all -o $@ $< + $(OUTPUT)/urandom_read: urandom_read.c urandom_read_aux.c $(OUTPUT)/liburandom_read.so $(call msg,BINARY,,$@) $(Q)$(CLANG) $(CLANG_TARGET_ARCH) \ @@ -463,6 +469,7 @@ RUNNER_PREREQS := $(INCLUDE_DIR)/vmlinux.h $(BPFOBJ) $(BPFTOOL) \ # Runtime fixtures for each test_progs flavor. RUNNER_EXTRA_FILES := $(OUTPUT)/urandom_read \ $(OUTPUT)/liburandom_read.so \ + $(OUTPUT)/liburandom_read_stripped.so \ $(OUTPUT)/xdp_synproxy \ $(OUTPUT)/sign-file \ $(OUTPUT)/uprobe_multi \ @@ -662,7 +669,8 @@ EXTRA_CLEAN := $(SCRATCH_DIR) $(HOST_SCRATCH_DIR) \ $(addprefix $(OUTPUT)/,*.o *.d *.skel.h *.lskel.h *.subskel.h \ *.BTF *.BTF_ids *.BTF.base \ no_alu32 cpuv4 bpf_gcc \ - liburandom_read.so) \ + liburandom_read.so \ + liburandom_read_stripped.so) \ $(OUTPUT)/FEATURE-DUMP.selftests .PHONY: docs docs-clean 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 7fbcfddc3..59f804d17 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,29 @@ static void test_attach_api_syms(void) test_attach_api("/proc/self/exe", NULL, &opts); } +/* + * A stripped shared library has .dynsym but no .symtab: every symbol is + * found in .dynsym, the missing .symtab must not turn that into -ENOENT. + */ +static void test_resolve_syms_no_symtab(void) +{ + const char *path = "./liburandom_read_stripped.so"; + const char *syms[2] = { + "urandlib_read_without_sema", + "urandlib_read_with_sema", + }; + unsigned long *offsets = NULL; + int err; + + err = elf_resolve_syms_offsets(path, ARRAY_SIZE(syms), syms, &offsets, + STT_FUNC); + if (!ASSERT_OK(err, "elf_resolve_syms_offsets")) + return; + ASSERT_GT(offsets[0], 0, "offset_without_sema"); + ASSERT_GT(offsets[1], 0, "offset_with_sema"); + free(offsets); +} + static void test_attach_api_fails(void) { LIBBPF_OPTS(bpf_link_create_opts, opts); @@ -1442,6 +1465,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("resolve_syms_no_symtab")) + test_resolve_syms_no_symtab(); if (test__start_subtest("link_api")) test_link_api(); if (test__start_subtest("link_api_path_fd")) -- 2.43.0