From: Jiri Olsa <olsajiri@gmail.com>
To: Hengqi Chen <hengqi.chen@gmail.com>
Cc: bpf@vger.kernel.org, ast@kernel.org, daniel@iogearbox.net,
andrii@kernel.org, alan.maguire@oracle.com, olsajiri@gmail.com
Subject: Re: [PATCH bpf-next v2 3/3] selftests/bpf: Add tests for symbol versioning for uprobe
Date: Sun, 10 Sep 2023 11:53:07 +0200 [thread overview]
Message-ID: <ZP2SA0ZWhh8t820l@krava> (raw)
In-Reply-To: <20230905151257.729192-4-hengqi.chen@gmail.com>
On Tue, Sep 05, 2023 at 03:12:57PM +0000, Hengqi Chen wrote:
> This exercises the newly added dynsym symbol versioning logics.
> Now we accept symbols in form of func, func@LIB_VERSION or
> func@@LIB_VERSION.
>
> The test rely on liburandom_read.so. For liburandom_read.so, we have:
>
> $ nm -D liburandom_read.so
> w __cxa_finalize@GLIBC_2.17
> w __gmon_start__
> w _ITM_deregisterTMCloneTable
> w _ITM_registerTMCloneTable
> 0000000000000000 A LIBURANDOM_READ_1.0.0
> 0000000000000000 A LIBURANDOM_READ_2.0.0
> 000000000000081c T urandlib_api@@LIBURANDOM_READ_2.0.0
> 0000000000000814 T urandlib_api@LIBURANDOM_READ_1.0.0
> 0000000000000824 T urandlib_api_sameoffset@LIBURANDOM_READ_1.0.0
> 0000000000000824 T urandlib_api_sameoffset@@LIBURANDOM_READ_2.0.0
> 000000000000082c T urandlib_read_without_sema@@LIBURANDOM_READ_1.0.0
> 00000000000007c4 T urandlib_read_with_sema@@LIBURANDOM_READ_1.0.0
> 0000000000011018 D urandlib_read_with_sema_semaphore@@LIBURANDOM_READ_1.0.0
>
> For `urandlib_api`, specifying `urandlib_api` will cause a conflict because
> there are two symbols named urandlib_api and both are global bind.
> For `urandlib_api_sameoffset`, there are also two symbols in the .so, but
> both are at the same offset and essentially they refer to the same function
> so no conflict.
>
> Signed-off-by: Hengqi Chen <hengqi.chen@gmail.com>
one nit below, but looks good
Acked-by: Jiri Olsa <jolsa@kernel.org>
thanks,
jirka
> ---
> tools/testing/selftests/bpf/Makefile | 5 +-
> .../testing/selftests/bpf/liburandom_read.map | 15 +++
> .../testing/selftests/bpf/prog_tests/uprobe.c | 95 +++++++++++++++++++
> .../testing/selftests/bpf/progs/test_uprobe.c | 61 ++++++++++++
> tools/testing/selftests/bpf/urandom_read.c | 9 ++
> .../testing/selftests/bpf/urandom_read_lib1.c | 41 ++++++++
> 6 files changed, 224 insertions(+), 2 deletions(-)
> create mode 100644 tools/testing/selftests/bpf/liburandom_read.map
> create mode 100644 tools/testing/selftests/bpf/prog_tests/uprobe.c
> create mode 100644 tools/testing/selftests/bpf/progs/test_uprobe.c
>
SNIP
> +void test_uprobe(void)
> +{
> + LIBBPF_OPTS(bpf_uprobe_opts, uprobe_opts);
> + struct test_uprobe *skel;
> + FILE *urand_pipe = NULL;
> + int urand_pid = 0, err;
> +
> + skel = test_uprobe__open_and_load();
> + if (!ASSERT_OK_PTR(skel, "skel_open"))
> + return;
> +
> + urand_pipe = urand_spawn(&urand_pid);
> + if (!ASSERT_OK_PTR(urand_pipe, "urand_spawn"))
> + goto cleanup;
> +
> + skel->bss->my_pid = urand_pid;
> +
> + /* Manual attach uprobe to urandlib_api
> + * There are two `urandlib_api` symbols in .dynsym section:
> + * - urandlib_api@LIBURANDOM_READ_1.0.0
> + * - urandlib_api@LIBURANDOM_READ_1.0.0
nit, should that be version 2.0.0? ^
> + * Both are global bind and would cause a conflict if user
> + * specify the symbol name without a version suffix
> + */
> + uprobe_opts.func_name = "urandlib_api";
> + skel->links.test4 = bpf_program__attach_uprobe_opts(skel->progs.test4,
> + urand_pid,
> + "./liburandom_read.so",
> + 0 /* offset */,
> + &uprobe_opts);
> + if (!ASSERT_ERR_PTR(skel->links.test4, "urandlib_api_attach_conflict"))
> + goto cleanup;
> +
> + uprobe_opts.func_name = "urandlib_api@LIBURANDOM_READ_1.0.0";
> + skel->links.test4 = bpf_program__attach_uprobe_opts(skel->progs.test4,
> + urand_pid,
> + "./liburandom_read.so",
> + 0 /* offset */,
> + &uprobe_opts);
> + if (!ASSERT_OK_PTR(skel->links.test4, "urandlib_api_attach_ok"))
> + goto cleanup;
> +
> + /* Auto attach 3 uprobes to urandlib_api_sameoffset */
> + err = test_uprobe__attach(skel);
> + if (!ASSERT_OK(err, "skel_attach"))
> + goto cleanup;
> +
> + /* trigger urandom_read */
> + ASSERT_OK(urand_trigger(&urand_pipe), "urand_exit_code");
> +
> + ASSERT_EQ(skel->bss->test1_result, 1, "urandlib_api_sameoffset");
> + ASSERT_EQ(skel->bss->test2_result, 1, "urandlib_api_sameoffset@v1");
> + ASSERT_EQ(skel->bss->test3_result, 1, "urandlib_api_sameoffset@@v2");
> + ASSERT_EQ(skel->bss->test4_result, 1, "urandlib_api");
> +
> +cleanup:
> + if (urand_pipe)
> + pclose(urand_pipe);
> + test_uprobe__destroy(skel);
> +}
SNIP
prev parent reply other threads:[~2023-09-10 9:53 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-05 15:12 [PATCH bpf-next v2 0/3] libbpf: Support symbol versioning for uprobe Hengqi Chen
2023-09-05 15:12 ` [PATCH bpf-next v2 1/3] libbpf: Resolve symbol conflicts at the same offset " Hengqi Chen
2023-09-08 14:30 ` Alan Maguire
2023-09-10 9:53 ` Jiri Olsa
2023-09-05 15:12 ` [PATCH bpf-next v2 2/3] libbpf: Support symbol versioning " Hengqi Chen
2023-09-08 15:07 ` Alan Maguire
2023-09-10 12:39 ` Hengqi Chen
2023-09-10 9:53 ` Jiri Olsa
2023-09-10 12:42 ` Hengqi Chen
2023-09-05 15:12 ` [PATCH bpf-next v2 3/3] selftests/bpf: Add tests for " Hengqi Chen
2023-09-08 14:40 ` Alan Maguire
2023-09-10 9:53 ` Jiri Olsa [this message]
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=ZP2SA0ZWhh8t820l@krava \
--to=olsajiri@gmail.com \
--cc=alan.maguire@oracle.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=hengqi.chen@gmail.com \
/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.