From: Hengqi Chen <hengqi.chen@gmail.com>
To: bpf@vger.kernel.org
Cc: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org,
alan.maguire@oracle.com, olsajiri@gmail.com,
hengqi.chen@gmail.com
Subject: [PATCH bpf-next v3 0/3] libbpf: Support symbol versioning for uprobe
Date: Mon, 11 Sep 2023 01:50:49 +0000 [thread overview]
Message-ID: <20230911015052.72975-1-hengqi.chen@gmail.com> (raw)
Dynamic symbols in shared library may have the same name, for example:
$ nm -D /lib/x86_64-linux-gnu/libc.so.6 | grep rwlock_wrlock
000000000009b1a0 T __pthread_rwlock_wrlock@GLIBC_2.2.5
000000000009b1a0 T pthread_rwlock_wrlock@@GLIBC_2.34
000000000009b1a0 T pthread_rwlock_wrlock@GLIBC_2.2.5
$ readelf -W --dyn-syms /lib/x86_64-linux-gnu/libc.so.6 | grep rwlock_wrlock
706: 000000000009b1a0 878 FUNC GLOBAL DEFAULT 15 __pthread_rwlock_wrlock@GLIBC_2.2.5
2568: 000000000009b1a0 878 FUNC GLOBAL DEFAULT 15 pthread_rwlock_wrlock@@GLIBC_2.34
2571: 000000000009b1a0 878 FUNC GLOBAL DEFAULT 15 pthread_rwlock_wrlock@GLIBC_2.2.5
There are two pthread_rwlock_wrlock symbols in libc.so .dynsym section.
The one with @@ is the default version, the other is hidden.
Note that the version info is stored in .gnu.version and .gnu.version_d
sections of libc and the two symbols are at the _same_ offset.
Currently, specify `pthread_rwlock_wrlock`, `pthread_rwlock_wrlock@@GLIBC_2.34`
or `pthread_rwlock_wrlock@GLIBC_2.2.5` in bpf_uprobe_opts::func_name won't work.
Because there are two `pthread_rwlock_wrlock` in .dynsym sections without the
version suffix and both are global bind.
We could solve this by introducing symbol versioning ([0]). So that users can
specify func, func@LIB_VERSION or func@@LIB_VERSION to attach a uprobe.
This patchset resolves symbol conflicts and add symbol versioning for uprobe.
- Patch 1 resolves symbol conflicts at the same offset
- Patch 2 adds symbol versioning for dynsym
- Patch 3 adds selftests for the above changes
Changes from v2:
- Add uretprobe selfttest (Alan)
- Check symbol exact match (Alan)
- Fix typo (Jiri)
Changes from v1:
- Address comments from Alan and Jiri
- Add selftests (Someone reminds me that there is an attempt at [1]
and part of the selftest code from Andrii is taken from there)
[0]: https://refspecs.linuxfoundation.org/LSB_5.0.0/LSB-Core-generic/LSB-Core-generic/symversion.html
[1]: https://lore.kernel.org/lkml/CAEf4BzZTrjjyyOm3ak9JsssPSh6T_ZmGd677a2rt5e5rBLUrpQ@mail.gmail.com/
Hengqi Chen (3):
libbpf: Resolve symbol conflicts at the same offset for uprobe
libbpf: Support symbol versioning for uprobe
selftests/bpf: Add tests for symbol versioning for uprobe
tools/lib/bpf/elf.c | 150 ++++++++++++++++--
tools/lib/bpf/libbpf.c | 2 +-
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 +++++
8 files changed, 361 insertions(+), 17 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
--
2.34.1
next reply other threads:[~2023-09-11 1:51 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-11 1:50 Hengqi Chen [this message]
2023-09-11 1:50 ` [PATCH bpf-next v3 1/3] libbpf: Resolve symbol conflicts at the same offset for uprobe Hengqi Chen
2023-09-11 1:50 ` [PATCH bpf-next v3 2/3] libbpf: Support symbol versioning " Hengqi Chen
2023-09-12 23:14 ` Andrii Nakryiko
2023-09-14 12:36 ` Hengqi Chen
2023-09-14 17:12 ` Andrii Nakryiko
2023-09-15 7:30 ` Hengqi Chen
2023-09-15 20:20 ` Andrii Nakryiko
2023-09-11 1:50 ` [PATCH bpf-next v3 3/3] selftests/bpf: Add tests for " Hengqi Chen
2023-09-12 23:19 ` Andrii Nakryiko
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=20230911015052.72975-1-hengqi.chen@gmail.com \
--to=hengqi.chen@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=olsajiri@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox