Skip to content

libbpf: Support symbol versioning for uprobe

Hengqi Chen bpf 4 versions – Applied

Status from this message: This series was applied to bpf/bpf-next.git (master)

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v4 Latest3 patches 2 repliesApplied 3/3
  2. v33 patches 6 repliesSuperseded
  3. v23 patches 8 repliesSuperseded
Earlier versions · 1
VersionPostedPatchesRepliesStatus
v12 patches4 repliesSuperseded

Changes in v4 from the cover letter

- Address comments from Andrii

Patches in v4 All 3 applied

#Subject and filesSizeRepliesApplied
1/3libbpf: Resolve symbol conflicts at the same offset for uprobetools/lib/bpf/elf.c+4 -10 repliesApplied
2/3libbpf: Support symbol versioning for uprobetools/lib/bpf/elf.c tools/lib/bpf/libbpf.c+124 -122 repliesApplied
3/3selftests/bpf: Add tests for symbol versioning for uprobetools/testing/selftests/bpf/Makefile tools/testing/selftests/bpf/liburandom_read.map tools/testing/selftests/bpf/prog_tests/uprobe.c +3 more+209 -40 repliesApplied

Reviews trailers per patch

All 3 patches have a Reviewed-by or Acked-by.

PatchAlan MaguireJiri Olsa
1/3R-b A-b
2/3R-b A-b
3/3R-b A-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v4 thread

Cover letter [PATCH bpf-next v4 0/3] libbpf: Support symbol versioning for uprobe

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 v3:
- Address comments from Andrii

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                           | 139 ++++++++++++++++--
 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    |  15 +-
 .../testing/selftests/bpf/urandom_read_lib1.c |  22 +++
 8 files changed, 337 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
Signature · 1 line
2.34.1